473,503 Members | 8,131 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(ByVal Table As String, Optional ByVal
SearchCrit As String = "")

If Table = "CustomerData" Then
'Build Data Adapter with Select Statement
Dim MySelect As String = "SELECT * FROM CustomerData"
DataAdapter = New OleDb.OleDbDataAdapter(MySelect,
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.OleDbDataAdapter(MySelect,
DataConnection)
End If

'Build the Insert, Delete, and Update statements
Dim cb As New OleDb.OleDbCommandBuilder(DataAdapter)

Debug.WriteLine("SELECT Command: " &
DataAdapter.SelectCommand.CommandText)

End Sub

'Now fill the dataset
DataAdapter.Fill(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=15293505
15293505 is found in the dataset. This seems so simple.
Anyway, Thanks for your time.
Carl Summers

Nov 21 '05 #1
1 1376
Hi,

You clear the second dataset before filling it.

mdsBracelets.Clear
DataAdapter.Fill(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(ByVal Table As String, Optional ByVal
SearchCrit As String = "")

If Table = "CustomerData" Then
'Build Data Adapter with Select Statement
Dim MySelect As String = "SELECT * FROM CustomerData"
DataAdapter = New OleDb.OleDbDataAdapter(MySelect,
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.OleDbDataAdapter(MySelect,
DataConnection)
End If

'Build the Insert, Delete, and Update statements
Dim cb As New OleDb.OleDbCommandBuilder(DataAdapter)

Debug.WriteLine("SELECT Command: " &
DataAdapter.SelectCommand.CommandText)

End Sub

'Now fill the dataset
DataAdapter.Fill(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=15293505
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
3528
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...
14
3246
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...
5
3250
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...
2
1383
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...
2
8154
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...
3
2739
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...
8
3464
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 ,...
5
8168
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...
1
2719
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...
0
7093
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...
0
7291
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
7357
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...
1
7012
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...
0
5598
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,...
1
5023
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...
0
3180
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...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
402
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...

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.