Part 3 We instantiate and Fill a new DataTable. Fill() will populate the internal rows and columns of the DataTable to match the SQL result.
Finally The DataSource is assigned to the DataTable. The result will be a filled DataGridView with data from SQL Server.
public partial class Form1 : Form
// Part 1: open connection.using (SqlConnection c = new SqlConnection( Properties.Settings.Default.DataConnectionString))
// Part 2: create new DataAdapter.using (SqlDataAdapter a = new SqlDataAdapter( "SELECT * FROM EmployeeIDs", c))
// Part 3: Use DataAdapter to fill DataTable.
DataTable t = new DataTable();
// Part 4: render data onto the screen.
// dataGridView1.DataSource = t;
Fill. Fill is the most important method on the DataAdapter objects. It executes the query and fills the DataAdapter object with the results.
Note OnFillError is an event that allows you to listen to when an error occurred when filling the DataTable.
Note 2 GetFillParameters() allows you to get the parameters that are being used in a SELECT statement.
Options. LoadOption is an enumeration of the options you can use when the DataAdapter is loaded. You can specify OverwriteChanges, PreserveChanges and Upsert.
Detail You code can use the AcceptChanges method when you want to accept all changes made to the row.
OnRowUpdated, OnRowUpdating. These events allow you to receive messages when the specified actions occur. They are useful when you must be alerted to changes.
A summary. We used SqlDataAdapter, part of the System.Data.SqlClient namespace. There are many members of SqlDataAdapter. We touched on SqlCeDataAdapter, which is similar.