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 "12345678901" 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 + "'";
OleDbDataAdapter da = new OleDbDataAdapter(strSql,conStr);
da.Fill(dt) //dt is a datatable declared earlier 5 4347
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****@dcferguson.com> wrote in message
news:f8**************************@posting.google.c om... 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 "12345678901" 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 + "'";
OleDbDataAdapter da = new OleDbDataAdapter(strSql,conStr); da.Fill(dt) //dt is a datatable declared earlier
> 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.
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 = "12345678901"
---
Taiwo
"Doug" <go****@dcferguson.com> wrote in message
news:f8**************************@posting.google.c om... 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 "12345678901" 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 + "'";
OleDbDataAdapter da = new OleDbDataAdapter(strSql,conStr); da.Fill(dt) //dt is a datatable declared earlier
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 "12345678901", 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
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****@dcferguson.com (Doug) wrote in message news:<f8**************************@posting.google. 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 "12345678901", which should not have been found. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |