最近 true または false を返すように関数を更新するまで機能していた以下のコードがあります。しかし、突然オブジェクト objReader が関数の外でアクセスできなくなりました。現在のクラスの任意のメソッドでアクセスできるようにします。
string strProvider = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + strCurWBPath + ";;Mode=ReadWrite" + @";Extended Properties=""Excel 8.0;HDR=Yes;""";
using ( objConn = new OleDbConnection(strProvider))
{
objConn.Open();
using ( objCmd = new OleDbCommand(strQuery, objConn))
{
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
objReader = objCmd.ExecuteReader(CommandBehavior.SequentialAccess);
// No point reading/writing data if there are no rows.
if (objReader.HasRows)
{
if (!objReader.IsClosed)
{
return true;
}
else
return false;
}
else
{
MessageBox.Show("There are no Rows to process. ");
}
}//end of using1
}//end of using2
助言がありますか ?