Hi,
I am using the C# as frontend and MS Access a backend.
I have a Insert statement to insert new records into the Access database, but how do i Update the dataset?
Printable View
Hi,
I am using the C# as frontend and MS Access a backend.
I have a Insert statement to insert new records into the Access database, but how do i Update the dataset?
Hi,
The approach that you are doing is quite the reverse. You must first edit your dataset then send the updates to your access database. To do this you must have a activeconnection, adapter and a dataset. eg:
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM myTable", con);
OleDbCommandBuilder cm = new OleDbCommandBuilder(adapter);
...
// Fill the DataSet and edit
adapter.Fill(ds);
ds.Tables[0].Rows[10]["field1"] = "TEsting";
// send updates to database
adapter.Update(ds);
I am using the insert command to update the database. so now How do u update the dataset? Do u refill it .
You can follow this method,
adapter.InsertCommand = new SqlCommand("INSERT INTO myTable VALUES(@Id)", conn);
adapter.InsertCommand.Parameters.Add("@Id", ...);
Sending Insert statements directly to the database is not a very good idea if your using a dataset. You must edit your dataset, then using your adapter, send the changes to your database.