Populating a DataSet with DataAdapter requires four steps
(1) Creating a Database Connection object
(2) Creating SQL statements for querying data from a database
(3) Create DataAdapter objects using the SQL statements and connection objects created above
Grammar:
SqlDataAdapter Object name = new SqlDataAdapter (query SQL statement, database connection);
Or
Sqldataadqpter adapter = new SqlDataAdapter ();
SqlCommand command = new SqlCommand (query SQL statement, database connection);
Adapter. SelectCommand = command;
(4) Call the Fill method of the DataAdapter object to populate the dataset
Grammar:
DataAdapter object. Fill (DataSet object, "data table name string");
The fill () method receives a string parameter for the name of a data table. If the data set does not already have the data table, a data table is created after the fill () method is called. If the data table is originally present in the DataSet, the results that are now detected will continue to be added to the data table.
Experience:
Creates a DataAdapter object that is related to the Connection.command object and writes the SQL statement
In different code snippets, the Connection object may appear in different locations