"SELECT" help needed with DataSets

  • Thread starter Thread starter bill salkin
  • Start date Start date
B

bill salkin

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 "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

What's next??


End Sub
 
You need the WHERE clause for example.

SELECT * FROM Customers WHERE City="London"


Tip: In Microsoft Access, build a query and then choose the View\SQL menu
option to see the SQL behind the query, you can copy and paste that into
your ADO.NET/VB.NET application.

Regards -OHM
 
Back
Top