私は自分のアプリケーションでこのメソッドを作成しましたが、正常に機能します。そのためのDLLファイルを作成することにしました。しかし、同じメソッドは、dll内のオブジェクトのインスタンスに設定されていないエラーオブジェクト参照を私に与えます。コードは
public void Try(string conStr, string storedProcedure)
{
try
{
//create a connection string
sqlCon = new SqlConnection(conStr);
// create command
sqlCmd = new SqlCommand(sqlCmd.CommandText, sqlCon);
//add command type
sqlCmd.CommandType = CommandType.StoredProcedure;
// add the stored procedure name
sqlCmd.CommandText = storedProcedure;
//Open connection
sqlCon.Open();
// Execute transaction
sqlCmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
// Close connection
sqlCon.Close();
}
エラーは次の場所で発生します:
sqlCmd = new SqlCommand(sqlCmd.CommandText, sqlCon);
何が問題になるのでしょうか?