By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 1,867 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Problem with OleDbCommand

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

On Sun, 10 Oct 2004 00:23:24 -0700, "Beringer"
<bo*********@invalid.com> wrote:
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


Nov 16 '05 #2

P: n/a
Hi Eric,

Have you tried

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

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3

P: n/a
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

"Beringer" <bo*********@invalid.com> wrote in message
news:Gr5ad.4595$kz3.4211@fed1read02...
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

Nov 16 '05 #4

P: n/a
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
"Beringer" <bo*********@invalid.com> wrote in message
news:Rwfad.4676$kz3.721@fed1read02...
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

"Beringer" <bo*********@invalid.com> wrote in message
news:Gr5ad.4595$kz3.4211@fed1read02...
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


Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.