Click to See Complete Forum and Search --> : OleDB SELECT with WHERE problems


andreasen
May 4th, 2004, 08:16 PM
Does anyone have any tips on how to perform a SELECT query with a WHERE clause in a C# windows app using oleDB connection? I've tried using the wizard to create a control that does this as well as doing it by hand
try
{
oleDbDataReader = oleDbSelectCommand.ExecuteReader();
}
catch (System.InvalidOperationException e)
{
}
while (oleDbDataReader.Read() == true)
{
< ... implement DB manipulation logic ... >
}

But this continues to generate the following OleDbExceptions:
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"

Since this is not listed in the ExecuteReader() exceptions, I'm not sure what is causing it or how to work-around it.

The test file attached is about as narrow as I can make it to demonstrate the problem. The DB (test.mdb) contains a table (BlockData) that has 2 columns (ID, Session - both numbers).

This is my first time implementing data access using VS.NET. Does anyone have experience with this type of problem in C# or VS.NET that can help me find a work-around. Thanks.
-b

hspc
May 5th, 2004, 01:35 AM
hi
1-make sure the database is in the bin\debug folder
2-change the Text property of label1 to the query string.

the form works fine now :)

andreasen
May 5th, 2004, 07:14 AM
Thanks for the feedback, but it looks like everything you changed was UI properties for the controls and did not modify in any way the DB interaction or query string.
When I replace my code with the new form1.cs source, and run it, I still get an exception when I click the checkbox and click the "Execute Query!!" button (after a few second delay).

Is it possible that the Jet DB driver I have is bad and yours is not?
-b

hspc
May 5th, 2004, 07:53 AM
surround Session with brackets:
label1.Text = "Select * FROM BlockData WHERE [Session]=2";
this way it worked
but brackets should be used with keywords..

I did not know that Session is a keyword !!!
also the query works fine in access without brackets !!!

andreasen
May 5th, 2004, 08:06 AM
Thank you, thank you, thank you!!!
Obviously I didn't realize Session was a keyword either.
-b