Problem with OleDbCommand

B

Beringer

Hello,

I am trying to make a query against an Access Database File using OleDb part
of the framework.
I created an SQL Query string using Access and it will execute the query
successfully in example SQL statement below:

SELECT * FROM myTable WHERE column1 Like "mytext*";

Now when I take that command and place it in an OleDbCommand as follows:

command.CommandText = "SELECT * FROM myTable WHERE column1 Like 'mytext*'";

And then execute a datareader with that command, the result is an empty set.
I've tried removing the single quotes " ' " from around the wildcard (i.e.
command.CommandText = "SELECT * FROM myTable WHERE column1 Like mytext*";)
and that generates an exception at run time.

Any ideas?

I have done similar queries using the SQL part of the framework and that
works ok for instance:
command.CommandText = "SELECT * FROM myTable WHERE column1 Like 'mytext%'";
works when the command is a SqlCommand.

Thank you in advance,
Eric
 
M

Morten Wennevik

Hi Eric,

Have you tried

"SELECT * FROM myTable WHERE column1 Like \"mytext*\""
 
J

JuLiE Dxer

Can't you just use the % for your wildcard character??


SELECT *
FROM myTable
WHERE column1 LIKE 'mytext%';

Of interest, if you swap the % in for the * when inside MS Access it
should return an empty table. Perhaps, that's exactly what's happening
with your situation. I always use % for wildcard with OleDb here.
 
B

Beringer

It is interesting I tried both ideas.
Placing literal " around the wildcard didn't work.
However, replacing the * with a % did. Now I thought % was SQL Server
specific and * was used in Access. Guess not.
Thanks for the input.
Eric
 
A

ambshah

you are right * is used in access , but here you are using oledb , i had a
similar problem when i used odbc and access , * worked in access but did not
work when i connected through odbc
fyi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top