|
-
October 29th, 2005, 09:04 AM
#1
Help. I cannot update mdb file.
I try to do it in a simple example.
File is present, opend.
Data accessable.
But no updates executed.
And runtime errors are absent too ;_(
OleDbConnection mConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\\Tmp.mdb");
OleDbCommand cmd = new OleDbCommand("SELECT t1.s1 FROM t1;", mConn);
mConn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow row = ds.Tables[0].NewRow();
row["s1"] = "aaa";
ds.Tables[0].Rows.Add(row);
ds.AcceptChanges();
OleDbCommandBuilder CommandBuilder = new OleDbCommandBuilder(da);
da.InsertCommand = CommandBuilder.GetInsertCommand();
da.Update(ds,"Table");
mConn.Close();
-
October 29th, 2005, 11:10 AM
#2
Re: Help. I cannot update mdb file.
Simply remove that line of code:
Code:
ds.AcceptChanges();
AcceptChanges method commits all changes made to dataset
and marks all new rows as unchanged. What's why dataadapter
doesn't updates anything. It's worth to mention that
DataAdapter's Update method internally calls AcceptChanges for
every row updated, therefore you don't need to call AcceptChanges
on dataset.
 Originally Posted by Alex Rest
I try to do it in a simple example.
File is present, opend.
Data accessable.
But no updates executed.
And runtime errors are absent too ;_(
OleDbConnection mConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\\Tmp.mdb");
OleDbCommand cmd = new OleDbCommand("SELECT t1.s1 FROM t1;", mConn);
mConn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow row = ds.Tables[0].NewRow();
row["s1"] = "aaa";
ds.Tables[0].Rows.Add(row);
ds.AcceptChanges();
OleDbCommandBuilder CommandBuilder = new OleDbCommandBuilder(da);
da.InsertCommand = CommandBuilder.GetInsertCommand();
da.Update(ds,"Table");
mConn.Close();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|