Data Adapter
The OleDbDataAdapter is
the thing that takes your data and provides an interface between the data and
the dataset. You create it like all of the others -
Dim
objAdapter as New OleDbDataAdapter("SELECT * FROM users", objConn)
|
Seems like the OleDbCommand but its not. You can use this Data Adapter for
things like Filling a dataset, Updating the data source with data from the
dataset and using SQL commands on the dataset. I'll take you through some of
these now.
Dim ds
as Dataset = New DataSet()
objAdapter.Fill(ds, "users") |
This method (fill) takes in the name of the dataset and the table in the
dataset to put it into. The table is created if it doesn't exist and then
populates it with the data that it got from the database using the query it
sent.
Mappings
Mapping allows you to
create an alias for the names of columns in the dataset. The names don't
affect the data source and when sending through the DataAdapter are
automatically converted.
objAdapter.TableMappings.Add("adbtable", "users")
With objAdapter.TableMappings(0).ColumnMappings
.Add("PID", "ID")
.Add("LastName", "LName")
.Add("StreetAddress", "Addy")
End With
objAdapter.Fill(ds) |
Now when you call the dataset you don't have to use
You can use
When we talk about datasets in Part 2, you'll see how this can come in useful
sometimes.