473,772 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String parameter in WHERE clause not providing exact matches.

I am exectuing a query (against an Access database) and the results
are not an exact match of the search criteria.

I have a list of packages saved in an Access file. Before doing
certain operations, I want to see if a tracking number has already
been saved to file.

The tracking number "1234567890 " is already stored in the file.
The tracking number "1234567890 1" is NOT in the file.

When I execute the query "Select * from Pkg WHERE TrackingNo =
'12345678901', nothing should be returned. Instead the record for
tracking number "1234567890 " is returned.

I thought that the '=' sign meant an exact match, but in this case
that is not what's happening.

For what it's worth the same query run in Access does not return any
records (which is the behavior I'm looking for). This leads me to
believe this is a c# issue and not an Access issue.
Any ideas?

TIA
Doug Ferguson

This is a snippet of the code:

string strSql = "Select * from Pkg where TrackingNo = '" +
this.TrackingNo + "'";

OleDbDataAdapte r da = new OleDbDataAdapte r(strSql,conStr );
da.Fill(dt) //dt is a datatable declared earlier
Nov 13 '05 #1
5 4364
Hello Doug,

Have you tried tracing the code and seeing exactly what is being set as
this.TrackingNO ? It could be that it is getting passed in as 1234567890
instead of 12345678901.

HTH,

Bill P.
"Doug" <go****@dcfergu son.com> wrote in message
news:f8******** *************** ***@posting.goo gle.com...
I am exectuing a query (against an Access database) and the results
are not an exact match of the search criteria.

I have a list of packages saved in an Access file. Before doing
certain operations, I want to see if a tracking number has already
been saved to file.

The tracking number "1234567890 " is already stored in the file.
The tracking number "1234567890 1" is NOT in the file.

When I execute the query "Select * from Pkg WHERE TrackingNo =
'12345678901', nothing should be returned. Instead the record for
tracking number "1234567890 " is returned.

I thought that the '=' sign meant an exact match, but in this case
that is not what's happening.

For what it's worth the same query run in Access does not return any
records (which is the behavior I'm looking for). This leads me to
believe this is a c# issue and not an Access issue.
Any ideas?

TIA
Doug Ferguson

This is a snippet of the code:

string strSql = "Select * from Pkg where TrackingNo = '" +
this.TrackingNo + "'";

OleDbDataAdapte r da = new OleDbDataAdapte r(strSql,conStr );
da.Fill(dt) //dt is a datatable declared earlier

Nov 13 '05 #2
> This leads me to believe this is a c# issue and not an Access issue.

I would suspect that its access's OleDB provider, not C#, where the issue
is. You might want to try your query from VB or VFP or something through
ADO.

Also, is the TrackingNo field big enough for all 11 characters? If its 10
characters long, and the query is "smart" it might truncate your query
parameter to that length, thus, finding the match. Thats just a wild guess
though.
Nov 13 '05 #3

Why don't you try the query in Access exactly as you constructed it in code.
I noticed that you used a single quote around the string. I recall that
access usually uses double quotes around strings; so set the query like so:

"Select * from Pkg WHERE TrackingNo = ""12345678901"" "

The above would pass the query to the provider as:

Select * from Pkg WHERE TrackingNo = "1234567890 1"

---
Taiwo

"Doug" <go****@dcfergu son.com> wrote in message
news:f8******** *************** ***@posting.goo gle.com...
I am exectuing a query (against an Access database) and the results
are not an exact match of the search criteria.

I have a list of packages saved in an Access file. Before doing
certain operations, I want to see if a tracking number has already
been saved to file.

The tracking number "1234567890 " is already stored in the file.
The tracking number "1234567890 1" is NOT in the file.

When I execute the query "Select * from Pkg WHERE TrackingNo =
'12345678901', nothing should be returned. Instead the record for
tracking number "1234567890 " is returned.

I thought that the '=' sign meant an exact match, but in this case
that is not what's happening.

For what it's worth the same query run in Access does not return any
records (which is the behavior I'm looking for). This leads me to
believe this is a c# issue and not an Access issue.
Any ideas?

TIA
Doug Ferguson

This is a snippet of the code:

string strSql = "Select * from Pkg where TrackingNo = '" +
this.TrackingNo + "'";

OleDbDataAdapte r da = new OleDbDataAdapte r(strSql,conStr );
da.Fill(dt) //dt is a datatable declared earlier

Nov 13 '05 #4
Thanks for the help, but I realized I did not fully understand how the
fill method worked with datatables. The error was not in the select
statement at all. Doh!

I thought the datatable would be repopluated *from scratch* when I
used the fill method. In other words, I thought the fill method would
repopulate the datatable *starting from the first row* each time the
method was called. It didn't work that way. Instead, it merely
appended the new query results to the existing datatable rows.

What happened was that I queried the file for the string "1234567890 ".
That string was found and was added to a new, empty datatable. Then,
I subsequently queried for the string "1234567890 1", which should not
have been found.

That string was NOT found and NOT added to the datatable. The one row
in the datatable was not from the second query, but was the row that
remained after my first query.

After running the second (unsuccessful) query, I looked at the
datatable and saw what turned out to be the results of the first
query. Because of the similarity in tracking numbers (and b/c I didn't
fully understand how .fill worked), I thought the SELECT statement was
misbehaving and acting like a "LIKE" SELECT instead of an "EXACT"
SELECT.

So...the SELECT statement worked just fine. It was the fill method
that got me.

Thanks again.
DF
Nov 13 '05 #5
Which brings me back to my earlier question about ado.net (and the
MS-provided examples specifically).. . Does anyone *really* program
that way? (that's a dig at the designers of ado.net - at Doug)

go****@dcfergus on.com (Doug) wrote in message news:<f8******* *************** ****@posting.go ogle.com>...
Thanks for the help, but I realized I did not fully understand how the
fill method worked with datatables. The error was not in the select
statement at all. Doh!

I thought the datatable would be repopluated *from scratch* when I
used the fill method. In other words, I thought the fill method would
repopulate the datatable *starting from the first row* each time the
method was called. It didn't work that way. Instead, it merely
appended the new query results to the existing datatable rows.

What happened was that I queried the file for the string "1234567890 ".
That string was found and was added to a new, empty datatable. Then,
I subsequently queried for the string "1234567890 1", which should not
have been found.

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4816
by: Richard T. Cunningham | last post by:
I've been using two instances of substr to pull an IP address out of a string. I know there's a more efficient way. Anyone? The string is like this: HOST 61.2.135.45 blocked. Richard
4
8747
by: mr_burns | last post by:
Hi there, I have a text box that I will use to search a database. I would like to use it so that it will not use a whole string (ie. 'red striped top') but instead break it up into individual words (ie. 'red', 'striped', 'top') and maybe put it into and array. I will then use the words in the array to search the database. How do I break a string up this way?
5
13377
by: Aamer Nazir | last post by:
Hi, I am having problems setting the value of a variable in a SQL String that I have to create dynamically in my procedure. The code that I currently have is as follows: set @sqlStatement='Set @compare_string=' + '(Select ' + @group_column_list_mod + ' from ' + @Tbl_Name + '_Sorted' + ' where Identity_Column=' + ltrim(rtrim(str(@loop_counter))) + ')'
4
8824
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where a * occurs in the string). This split function should allocate a 2D array of chars and put the split results in different rows. The listing below shows how I started to work on this. To keep the program simple and help focus the program the...
4
13643
by: Jason Gleason | last post by:
What's the most efficient way to get the number of occurences of a certain string in another string..for instance i'm using the following code right now... private int CharacterCounter(String text,String Character) { int count = 0;
32
14893
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
5
1768
by: jim_geissman | last post by:
An application filters records based on names found in them. For example, looking through property buyer names, looking for banks and relocation companies. I have a table of names and patterns: CREATE TABLE #Filters (Pattern varchar(100), IfWildCard int, Category int) INSERT #Filters SELECT 'Bank Of America', 0, 1 INSERT #Filters SELECT '% Bank %', 1, 2
4
2667
by: Phil Latio | last post by:
I'm kind of looking for some guidance in respect of this obstacle I'm up against - please let me expand; I have an option group with three options (AND, OR, & NONE) and a text box which will accept free text - the text will become criteria in a SQL string and depending upon the option the WHERE clause will be AND/OR LIKE textCriteria1 AND/OR LIKE textCriteria2.... I'm trying to create a VBA function to take the free text and break up...
9
2682
by: | last post by:
I am interested in scanning web pages for content of interest, and then auto-classifying that content. I have tables of metadata that I can use for the classification, e.g. : "John P. Jones" "Jane T. Smith" "Fred Barzowsky" "Department of Oncology" "Office of Student Affairs" "Lewis Hall" etc. etc. etc. I am wondering what the efficient way to do this in code might be. The dumb and brute-force way would be to loop through the content...
0
9619
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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
10103
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...
0
8934
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 project—planning, coding, testing, and deployment—without 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
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
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.