I have the below code which used to work until i recently updated the function to return true or false.But suddenly the object objReader stopped being accessible outside the function.I have declared in the beginning of the class as private static oledbdatareader = null; So that i can access it in any method in the current class.
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
any suggestions ?