
Filling a Dataset Using a TableAdapter
You can call a query on the TableAdapter to load data into data tables in a dataset. Pass the DataTable you want to fill to the TableAdapter query. If your query takes parameters, pass those to the method as well. If the dataset contains multiple tables, you should have separate TableAdapters for each table and must therefore fill each table separately.
Note: |
|---|
By default, every time you execute a TableAdapter query, the data in the table is cleared prior to the results of the query being loaded into the table. You can keep the existing data in the table and append the results by setting the TableAdapter's
ClearBeforeFill property to false.
|
To fill a dataset with data using a TableAdapter
Open your form or component in the Code Editor.
Add code anywhere in your application where you need to load a data table with data. If your query does not take parameters, pass in the DataTable you want to fill. The code should look similar to the following:
Me.CustomersTableAdapter.Fill(Me.NorthwindDataSet.Customers)
this.customersTableAdapter.Fill(this.northwindDataSet.Customers);
If your query takes parameters, pass in the DataTable you want to fill and the parameters expected by the query. Depending on the actual parameters in your query, the code would look similar to the following examples:
CustomersTableAdapter.FillByCity(NorthwindDataSet.Customers, "Seattle")
CustomersTableAdapter.FillByCityAndState(NorthwindDataSet.Customers, "Seattle", "WA")
customersTableAdapter.FillByCity(northwindDataSet.Customers, "Seattle");
customersTableAdapter.FillByCityAndState(northwindDataSet.Customers, "Seattle", "WA");