Can't figure out where clause in sql statement.

L

Locke

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
 
G

Guest

Hi,

You clear the second dataset before filling it.

mdsBracelets.Clear
DataAdapter.Fill(mdsBracelets, "Bracelets")

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top