Multi-criteria SELECT Dataset Quesion

  • Thread starter Thread starter NoDoze Bill
  • Start date Start date
N

NoDoze Bill

The code below creates a dataset containing a table
called "Customers" from the Northwind database

Later on in my code, after the database connection is
closed, I need to access this dataset to get all
records with both "ContactTitle" = 'Owner' and "City"
= 'London'.

I have tried using the SELECT and Find methods of dataset
techbnology but I can't make them work with multi-
criteria queries.Help!


Bill

P.S. This is strictly a data import problem. I have no
datagrid controls to "bind" the records to. I need the
records back in a "loop-friendly" structure where I can
access them one by one.


Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click

' Open a connection to the database.
Dim strConnection As String = _
"Data Source=localhost; Initial
Catalog=Northwind;" _
& "Integrated Security=True"

Dim cn As SqlConnection = New SqlConnection(strConnection)
cn.Open()

' Set up a data set command object.
Dim strSelect As String = "SELECT * FROM Customers"
Dim dscmd As New SqlDataAdapter(strSelect, cn)

' Load data set.
Dim ds As New DataSet
dscmd.Fill(ds, "Customers")


' Close the connection.
cn.Close()

' Get all records in dataset matching ContactTitle, City
criteria.

' How can i do this?

' For testing purposes display neames using
' Console.Writeline




End Sub
 
I've used the Select method to retrieve data that had more then one clause
in it.

myTable.Select("Col1='val1' and col2='val2'")
 
Hello Nodoze...

the way you are constructing the Select() statement is the problem.

change ("ContactTitle" = 'Owner' and "City" = 'London' ) to ("ContactTitle
= 'Owner' AND City = 'London'")
and it should work fine.

If you are working with values contained in variables you could do this
instead:

..Select("ContactTitle = '" & ContactTitleValue & "' AND City = '" &
CityValue & "'")


--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx
 
Back
Top