-2
我有下面的代碼,它曾經工作,直到我最近更新函數返回true或false。但突然間對象objReader停止在函數外可訪問。我已聲明在課程開始時作爲私人靜態oledbdatareader = null;以便我可以在當前課程中的任何方法中訪問它。oledbdatareader不能在C#中的函數之外訪問.net代碼
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
有什麼建議嗎?