-
Writing to Database
Hi,
I load a table data from my database using dataAdapter.Fill(dataset) method, and then using datarow to edit the records.
I want to use datarow.BeginEdit() for every row, and finally call dataadapter.Update(dataset) to write into database. The problem is the updated data is only written to datatable/dataset but never written to database. What is the problem?
If i just edit the record by record and followed by a call to dataadapter.Update(dataset), the data is written to database.
Can anyone give me a sample of how to use BeginEdit() to write data to database? I searched the internet but all is about using BeginEdit to edit the record and write to datatable only, not to permanent database.
-
Re: Writing to Database
Please provide the stored procedure and the function you use to access the database.
-
Re: Writing to Database
Btw, i am using firebird database, but i guess any database will be the same method. The modified data can be seen from the dataset, but it just doesn't get written into database after accept changes on dataset.
Code:
FbCommandBuilder myCommandBuilder = null;
FbConnection ObjConnection = null;
DataSet dataSet = null;
FbDataAdapter ObjDataAdapter = null;
FbConnection ObjConnection = new FbConnection(connectionString);
FbCommand ObjCommand = new FbCommand("SELECT * FROM myTable", ObjConnection);
ObjDataAdapter = new FbDataAdapter(ObjCommand);
myCommandBuilder = new FbCommandBuilder(ObjDataAdapter);
dataSet = new DataSet();
ObjDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
ObjDataAdapter.Fill(dataSet, "myTable");
DataRow dr = null;
dr = dataSet.Tables["myTable"].Rows.Find(index);
if (dr!= null)
{
dr.BeginEdit();
dr["myCol"] = (double)dr["myCol"] + 1; ;
//double x = (double)dr["myCol", DataRowVersion.Current];
//double y = (double)dr["myCol", DataRowVersion.Proposed];
}
dataSet.AcceptChanges();