here one thing to remember is updating dataset will not update database. adapter.Fill(dataset,"Students"); DataTable table = dataset.Tables["Students"]; DataRow [] rows = table.select("Roll = 3"); DataRow row = rows[0]; row["Name"] = "Bond"; so, here it updates dataset but not data base . instead if you feel dataset to be updated to database then we use adapter with dataset. adapter.Update(dataset)
The DataAdapter object uses commands to update the data source after changes have been made to the DataSet. Using the Fill method of the DataAdapter calls the SELECT command; using the Update method calls the INSERT, UPDATE or DELETE command for each changed row. You can explicitly set these commands in order to control the statements used at runtime to resolve changes, including the use of stored procedures. For ad-hoc scenarios, a CommandBuilder object can generate these at run-time based upon a select statement. However, this run-time generation requires an extra round-trip to the server in order to gather required metadata, so explicitly providing the INSERT, UPDATE, and DELETE commands at design time will result in better run-time performance.
SqlConnection con=new SqlConnection("server=localhost;Trusted_Connection=yes;database=northwind");SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("select * from customers", myConnection);SqlDataAdapter sda = new SqlDataAdapter("select * from customers", con);
sda.InsertCommand.CommandText = "sp_InsertCustomer";sda.InsertCommand.CommandType = CommandType.StoredProcedure;sda.DeleteCommand.CommandText = "sp_DeleteCustomer";sda.DeleteCommand.CommandType = CommandType.StoredProcedure;sda.UpdateCommand.CommandText = "sp_UpdateCustomers";sda.UpdateCommand.CommandType = CommandType.StoredProcedure;