R
RMittelman
Guest
I'm trying to make a data service which can select data from various databases. I'm using c# and starting with an Access database.
I'm able to connect to the database, and execute a Select statement such as:
Select * From MyTable Where MyID < 4
My code properly returns a DataTable with the proper records. But, to use best practices, I want to execute the query with parameters, such as the following, and add a parameter to the ADO.Net Command object which contains the actual value of the ID (4 in this case).
Select * From MyTable Where MyID < @MyID
Of course this doesn't work with Access, because it doesn't recognize the @ syntax for parameters. I tried to make it more Access-friendly like this:
Select * From MyTable Where MyID < [IdParameter]
Then I add a parameter with the value 4 to the command's Parameters collection, with the name of "IdParameter". When I execute the code, I get this result:
ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
So this shows that I'm not properly loading the command with the parameter, or Access just won't work that way using a Select statement. Is there any way to get this to work properly with Access? Thanks...
Ron Mittelman
Continue reading...
I'm able to connect to the database, and execute a Select statement such as:
Select * From MyTable Where MyID < 4
My code properly returns a DataTable with the proper records. But, to use best practices, I want to execute the query with parameters, such as the following, and add a parameter to the ADO.Net Command object which contains the actual value of the ID (4 in this case).
Select * From MyTable Where MyID < @MyID
Of course this doesn't work with Access, because it doesn't recognize the @ syntax for parameters. I tried to make it more Access-friendly like this:
Select * From MyTable Where MyID < [IdParameter]
Then I add a parameter with the value 4 to the command's Parameters collection, with the name of "IdParameter". When I execute the code, I get this result:
ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
So this shows that I'm not properly loading the command with the parameter, or Access just won't work that way using a Select statement. Is there any way to get this to work properly with Access? Thanks...
Ron Mittelman
Continue reading...