I\'ve been reading through the MSDN resources and several forums and still don\'t understand what\'s the difference between those two dataAdapter.Fill()
and
For short the definition.
DataAdapter.Fill()
stands for SELECT query statement to database from the Server.
// 1
// Open connection
using (SqlConnection c = new SqlConnection(
Properties.Settings.Default.DataConnectionString))
{
c.Open();
// 2
// Create new DataAdapter
using (SqlDataAdapter a = new SqlDataAdapter("SELECT * FROM EmployeeIDs", c))
{
// 3
// Use DataAdapter to fill DataTable
DataTable t = new DataTable();
a.Fill(t);
// 4
// Render data onto the screen
// dataGridView1.DataSource = t; // <-- From your designer
}
}
DataAdapter.Update()
stands for Update, Insert and Delete query statement to database from the Server.
public DataSet CreateCmdsAndUpdate(DataSet myDataSet,string myConnection,string mySelectQuery,string myTableName)
{
OleDbConnection myConn = new OleDbConnection(myConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();
myDataAdapter.SelectCommand = new OleDbCommand(mySelectQuery, myConn);
OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter);
myConn.Open();
DataSet custDS = new DataSet();
myDataAdapter.Fill(custDS);
//code to modify data in dataset here
//Without the OleDbCommandBuilder this line would fail
myDataAdapter.Update(custDS);
myConn.Close();
return custDS;
}
Reference:
C# SqlDataAdapter
DataAdapter.Update Method