0

using に使用したいsql command

using(SqlCommand command = new SqlCommand("usp_UpdateUser", _sqlConnection, _sqlTransaction))
{
   ....
}

しかし、FillCommand(ref command)例外が発生しています:

Cannot pass command as ref or out variable because it is using variable.

私のコードは次のとおりです。

SqlCommand command = new SqlCommand("usp_UpdateUser", _sqlConnection,  
          _sqlTransaction);

command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int)).Value = Id;

FillCommand(ref command);
try
{
     command.ExecuteNonQuery();
}
catch
{
     throw;
}
4

1 に答える 1

2

以来

FillCommand 

あなたが書いた関数であり、それをvoid関数として使用している場合、パラメーターとして渡す代わりにコマンドを返すように変更できrefます。

次のようなものを使用します。

using(SqlCommand command = FillCommand("usp_UpdateUser", _sqlConnection, _sqlTransaction, CommandType.StoredProcedure))
{
   ...
}
于 2013-01-08T09:40:40.657 に答える