3
Answers

Unable to access MDB file using OleDbConnection

Kok Keong Chua

Kok Keong Chua

13y
3.4k
1
Hi,
I need help to resolve this problem:

I would like to access a MDB file and query some data from it, under the debug mode, Locals window, I'm able to see the data inside the reader object if i query for the whole table using the syntax as shown below:

using (OleDbConnection AccessConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=C:\PVCTData\Measurement_Result.mdb"))

             

 {
     OleDbCommand cmd = new OleDbCommand("SELECT * FROM Results order by TestTimeDate", AccessConnection);
     AccessConnection.Open();
     OleDbDataReader reader;
      reader = cmd.ExecuteReader();
      MessageBox.Show(reader.GetValue(0).ToString());
      reader.Close();
      AccessConnection.Close();
       return sn;
}

however, if i just want to retrieve one record by using the query "SELECT top1 CellIDStr FROM Results order by TestTimeDate", the program will throw an exception:

exception    {"No data exists for the row/column."}  
System.Exception {System.InvalidOperationException}


May i know what is the problem in my code? Thanks.
Answers (3)