473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with OleDbCommand

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
4 4673
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
Hi Eric,

Have you tried

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

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JenU | last post by:
Hi! Running DB2 Connect EE 8.1 on Windows 2000. When we execute a web app with a small amount of data returned, we do not have a problem. But, when we widen the criteria, we get errors... web...
2
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview....
1
by: thangchan | last post by:
Hi all, i am getting SQL update problem. as below ======================error messages ======================= Server Error in '/CMS' Application....
2
by: explode | last post by:
I made nova oledbdataadapter select update insert and delete command and connection veza. dataset is Studenti1data, I made it by the new data source wizard,and made datagridview and bindingsource...
5
by: explode | last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) that creates a new oledbDataAdapter with insert update select and delete commads. I also added that commands can...
7
by: Richard S | last post by:
alright, first of all i love thise site, helped me out alot alreaddy, but now i have a problem witch i cant find a answer to after a LONG time of searching. I am trying to make a small search,...
1
by: dhyder | last post by:
OK, like the title says my error is Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. I have looked into this a lot, but have not...
10
by: Ben | last post by:
Hi, i have a weird problem and i don't know who is responsible for this: IIS, excel or asp.net. My problem: we use an asp.net 2.0 application under IIS 6.0 (server 2003 sp2) which must write...
2
by: johnmay1248 | last post by:
I am having a problem with queries running in this code When I use the query "SELECT * FROM sample" the code runs and the data grid binds and shows the contents of the sample table. If I change...
0
by: GR M | last post by:
I'm having problem With a Null reference exception Error message when running the later part of the code. i.e trans.Rollback() FYI: Dim trans As OleDbTransaction Try ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.