Kok Keong Chua

Kok Keong Chua

  • NA
  • 15
  • 21.4k

Unable to access MDB file using OleDbConnection

May 12 2011 10:24 AM
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)