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 dataAdapter.Update()
, I tried to use both of them to update the database from my program and it works, but when I try to remove the update()
function, it is still working perfectly, therefore I think of it as useless.
Can anyone please clarify this?
Edit: this is my code to delete:
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Public\\Documents\\inventorySystem\\branches\\Database\\inventorySystemDatabase.accdb";
string query = "DELETE FROM Product WHERE product_id=" + productDataGridView[1, e.RowIndex].Value.ToString();
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
OleDbCommandBuilder deleteBuilder = new OleDbCommandBuilder(dAdapter);
DataTable deleteTable = new DataTable();
dAdapter.Update(deleteTable);
-- I have to make an extra select command to update the datagridview --
For short the definition.
DataAdapter.Fill()
stands for SELECT query statement to database from the Server.DataAdapter.Update()
stands for Update, Insert and Delete query statement to database from the Server.Reference:
C# SqlDataAdapter
DataAdapter.Update Method
Working sample
In simple words.
DataAdapter.Fill() is used to load data from database
Example : Showing Data From database to gridview
and once the edits are done, the DataAdapter.Update() commits all the changed data information to the database using the underlying connection.
DataAdapter.Fill()
DataAdapter.Update()