473,569 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't figure out where clause in sql statement.

I know I'm doing something wrong, and it's something simple but I can't
figure it out. I'm new at this and it's only a little more than a
hobby so please bear with me.

I'm writing a VB shell around an Access database. I have an object
that handles the communication of data between my main form and the
database. It creates a oledb data connection, - no problems. It then
builds an adapter and fills a dataset of customer information, - no
problems. However, it then recreates the adapter and fills a dataset
with information from a second table. There's actually no problem with
this except when I try to filter the data being populated into the
second dataset. Here's the most relevent code of the project:

'Build Data Adapter
Private Sub BuildAdapter(By Val Table As String, Optional ByVal
SearchCrit As String = "")

If Table = "CustomerDa ta" Then
'Build Data Adapter with Select Statement
Dim MySelect As String = "SELECT * FROM CustomerData"
DataAdapter = New OleDb.OleDbData Adapter(MySelec t,
DataConnection)
ElseIf Table = "Bracelets" Then
Dim MySelect As String
If SearchCrit = "" Then
MySelect = "SELECT * FROM Bracelets"
Else
MySelect = "SELECT * FROM Bracelets WHERE CustNum=" &
SearchCrit
End If
DataAdapter = New OleDb.OleDbData Adapter(MySelec t,
DataConnection)
End If

'Build the Insert, Delete, and Update statements
Dim cb As New OleDb.OleDbComm andBuilder(Data Adapter)

Debug.WriteLine ("SELECT Command: " &
DataAdapter.Sel ectCommand.Comm andText)

End Sub

'Now fill the dataset
DataAdapter.Fil l(mdsBracelets, "Bracelets" )

The value passed to build adapter for searchcrit is a number ie; 12345
, no quotes. The output of the debug.writeline is: SELECT Command:
SELECT * FROM Bracelets WHERE CustNum=1529350 5
15293505 is found in the dataset. This seems so simple.
Anyway, Thanks for your time.
Carl Summers

Nov 21 '05 #1
1 1388
Hi,

You clear the second dataset before filling it.

mdsBracelets.Cl ear
DataAdapter.Fil l(mdsBracelets, "Bracelets" )

Ken
----------------------------
"Locke" wrote:
I know I'm doing something wrong, and it's something simple but I can't
figure it out. I'm new at this and it's only a little more than a
hobby so please bear with me.

I'm writing a VB shell around an Access database. I have an object
that handles the communication of data between my main form and the
database. It creates a oledb data connection, - no problems. It then
builds an adapter and fills a dataset of customer information, - no
problems. However, it then recreates the adapter and fills a dataset
with information from a second table. There's actually no problem with
this except when I try to filter the data being populated into the
second dataset. Here's the most relevent code of the project:

'Build Data Adapter
Private Sub BuildAdapter(By Val Table As String, Optional ByVal
SearchCrit As String = "")

If Table = "CustomerDa ta" Then
'Build Data Adapter with Select Statement
Dim MySelect As String = "SELECT * FROM CustomerData"
DataAdapter = New OleDb.OleDbData Adapter(MySelec t,
DataConnection)
ElseIf Table = "Bracelets" Then
Dim MySelect As String
If SearchCrit = "" Then
MySelect = "SELECT * FROM Bracelets"
Else
MySelect = "SELECT * FROM Bracelets WHERE CustNum=" &
SearchCrit
End If
DataAdapter = New OleDb.OleDbData Adapter(MySelec t,
DataConnection)
End If

'Build the Insert, Delete, and Update statements
Dim cb As New OleDb.OleDbComm andBuilder(Data Adapter)

Debug.WriteLine ("SELECT Command: " &
DataAdapter.Sel ectCommand.Comm andText)

End Sub

'Now fill the dataset
DataAdapter.Fil l(mdsBracelets, "Bracelets" )

The value passed to build adapter for searchcrit is a number ie; 12345
, no quotes. The output of the debug.writeline is: SELECT Command:
SELECT * FROM Bracelets WHERE CustNum=1529350 5
15293505 is found in the dataset. This seems so simple.
Anyway, Thanks for your time.
Carl Summers

Nov 21 '05 #2

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

Similar topics

7
3536
by: diroddi | last post by:
I am having a problem using a dynamic where clause. I have a feeling that I am overlooking something very simple, although I can't seem to figure it out. The error i'm getting is: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY full_name ASC...
14
3250
by: joshsackett | last post by:
I have a WHERE clause that could be an "=" or a "LIKE" depending upon if the passed variable is populated or not. I would like to know the best way to write the WHERE clause to make it dynamically switch between the 2 and make best use of the indexes. CREATE TABLE myTable(ID INT PRIMARY KEY CLUSTERED, COUNTY VARCHAR(50)) CREATE INDEX...
5
3259
by: Bob Sparks | last post by:
I upgraded to stinger and got stung. Not all my code compiles. Most of the problems are stinger seems to be more stringent on casting varchars to vargraphics. This I am working out, however, one procedure fails to compile and gives the following message. SQL0901N The SQL statement failed because of a non-severe system error. Subsequent...
2
1388
by: kuhni | last post by:
Hi everybody, I have a problem with my SQL-Statement: SELECT * FROM WHERE (((Year > 2003) And (Month <= 6)) Or (Year = 2003)) The WHERE-clause doesn't work properly. As result I receive all entries from 2003 and 2004 where the month is <= 6.
2
8161
by: Robert | last post by:
I am trying to give the user dynamic search capabilities to select almost any record in the database from criteria they select. Everything seems to work except when I open the display form to display the data to the user. If that form is already open, how do I make it refresh its data source and display the new data. Here is what I am...
3
2740
by: Mike Charney | last post by:
I am having trouble with the where clause in an openreport statement in an Access Data Project. I am using MS-Access 2003 with SQL Svr 2000. The line I am using is: DoCmd.OpenReport "rptAllRecords", acViewPreview, , "=" 'True' When I hit the button that is supposed to open the report I get the
8
3468
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 , etc. I want to go to the first row, do a WHERE statement, return the
5
8177
by: clear1140 | last post by:
Good day!! I was wondering if it is possible to put an if else statement inside a where clause of an sql statement... you see i would like my update statement to do this: update trial_clear set num = @count2 /* @count2 is a integer passed*/ where if (select top 1 def from trial_clear where num is NULL) is NULL def is...
1
2725
by: ebo2006 | last post by:
There are two combo boxes in my form: CORP and CLASS. The WHERE clause of the SELECT statement in the Row Source Property of the CLASS combo box works only every time I start the form. It does not change the list options when I select another ID from CORP combo box. Why is this so? Here is my select statement SELECT ., . FROM Courses WHERE...
0
7701
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...
0
7615
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...
0
7924
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. ...
0
8130
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...
1
7677
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...
1
5514
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
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...
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
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...

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.