SqlCommandには次のパラメーターがあります。ストアドプロシージャのパラメータ値を入力および出力する方法を教えてください。
SqlCommand mySqlCommand = new SqlCommand("aspInsertZipCode", mySqlConnection);
mySqlCommand.CommandType = CommandType.StoredProcedure;
mySqlCommand.Parameters.Add("@DataRows", dataStringToProcess.ToString());
var pInOut = mySqlCommand.Parameters.Add("@DataRows", dataStringToProcess.ToString());
pInOut.Direction = ParameterDirection.InputOutput;
そして、コマンドを実行した後に出力値を読み取るには、次のようにします。
// assumes that the parameter is a string and that it could possibly be null
string value = Convert.IsDBNull(pInOut.Value) ? null : (string)pInOut.Value;
SqlParameter
にはDirection
列挙があります。この値を設定します。
次に、SqlParameter
を取る_SqlCommand.Parameters.Add
_を使用します。
パラメータの方向:
http://msdn.Microsoft.com/en-us/library/system.data.parameterdirection.aspx
次に、コマンドコレクションからパラメータからExecuteNonQuery
を取得することにより、(たとえば)Value
を呼び出した後に値を引き出します。
_myCommand.Parameters["@paramName"].Value
_
思い出せませんが、文字列インデクサがあると思います。
または、この1つのライナーがあります:
myCommand.Parameters.AddWithValue("@paramName", value).Direction = ParameterDirection.InputOutput;
SQLコマンドパラメータの属性の1つは、方向です。あなたが使いたいと思うでしょう(メモリを使い果たします)
SqlCommand mySqlCommand = new SqlCommand("aspInsertZipCode", mySqlConnection);
mySqlCommand.CommandType = CommandType.StoredProcedure;
mySqlCommand.Parameters.Add("@DataRows", dataStringToProcess.ToString());
mySqlCommand.Parameters("@DataRows").Direction = ParameterDirection.InputOutput;
SqlParameter DataRows = new SqlParameter("@DataRows", SqlDbType.Text)
{ Value = dataStringToProcess.ToString(), Direction = ParameterDirection.InputOutput};
mySqlCommand.Parameters.Add(DataRows);