473,666 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Command Text = "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.Command Text = "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.Command Text = "SELECT * FROM myTable WHERE column1 Like 'mytext%'";
works when the command is a SqlCommand.

Thank you in advance,
Eric
Nov 16 '05 #1
4 4683
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*********@in valid.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.Comman dText = "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.Comman dText = "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.Comman dText = "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*********@in valid.com> wrote in message
news:Gr5ad.4595 $kz3.4211@fed1r ead02...
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.Command Text = "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.Command Text = "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.Command Text = "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*********@in valid.com> wrote in message
news:Rwfad.4676 $kz3.721@fed1re ad02...
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*********@in valid.com> wrote in message
news:Gr5ad.4595 $kz3.4211@fed1r ead02...
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.Command Text = "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.Command Text = "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.Command Text = "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
1669
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 app shows: Exception caught in TFBDB, DoDB2Dataset - DotNet Provider. Exception Message - SQL1224N A database agent could not be started to service a request, or was terminated as a result of a database system shutdown or a force command....
2
1604
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. The following control simply responds to a sort request and/or a pageing reqeust with an empty table (header only). Any ideas ? Code behind : namespace OakTree.data {
1
4965
by: thangchan | last post by:
Hi all, i am getting SQL update problem. as below ======================error messages ======================= Server Error in '/CMS' Application. -------------------------------------------------------------------------------- 無值提供給一或多個必要參數。 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
2
2924
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 draging Table1 to Form2. The select command works fine, but when I change the data and call update command I get a syntax error: System.Data.OleDb.OleDbException was unhandled ErrorCode=-2147217900 Message="Syntax error in UPDATE statement."...
5
2162
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 change depending how many columns are in a Table. I add a new column with this code: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try...
7
1720
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, witch will search true my database table called "serials" in the colum "SoftwareName" for a match. but im having the biggest trouble in making it work. this is my code atm: protected void btn_search_Click(object sender, EventArgs e) { ...
1
3058
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 been able to find a solution to it. <%@ Page Language="c#" runat="server" debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script runat="server"> OleDbConnection conn = new...
10
2913
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 data from a form into a table in excel files (i know excel is not really recommended for that, but it's excel).There are a lot of excel files, all in the same directory with the same privileges (Network service has
2
1531
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 the query to filter the results such as "SELECT * FROM sample WHERE (sales 2000)" the code fails on - objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) with an unknown error. If I load the database up into access2000...
0
1021
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 trans = con.BeginTransaction
0
8448
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.