Datasheet

Now when you look at the WHERE clause section you see two tables joined together as in Figure 8-17:
Figure 8-17
The
WHERE Clause Builder can also be used to filter data so that only selected rows are shown; we'll look
at that later. For now though, let's move on to look at the code the wizard created for us (it may look
slightly different in your page – we've wrapped it so it's easier to read):
Function GetProductsDataSet() As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Ole DB Services=-4; Data Source=C:\BegASPNET11\" & _
"data\Northwind.mdb"
Dim dbConnection As System.Data.IDbConnection = _
New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString As String = "SELECT [Products].[ProductName], " & _
"[Categories].[CategoryName] FROM [Products], "[Categories] " & _
"WHERE ([Categories].[CategoryID] = [Products].[CategoryID])"
Dim dbCommand As System.Data.IDbCommand = _
New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = _
New System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
Let's tackle this in stages. First we have the function declaration:
Function GetProductsDataSet() As System.Data.DataSet
This is defined as type System.Data.DataSet, which means it's going to return a DataSet (we'll look
at this in detail in the next chapter). You'll notice that the declaration has the namespace
System.Data
before it. This is done because while declaring variables or functions, ASP.NET needs to know where the
type is stored.
272
Chapter 8
57076_Ch 8 SAN.qxd 01/12/2003 6:43 PM Page 272