G
Grober
Hi,
The code below is working all the way. The problem is that the Update method
of the adapter doesn't update the mdb database. What am I doing wrong,
anyone?
string path = Path.GetDirectoryName(Application.ExecutablePath);
string sConn = @"provider=Microsoft.Jet.OLEDB.4.0;data
source=c:\temp\testxp.mdb";
OleDbConnection conn = new OleDbConnection(sConn);
OleDbDataAdapter adp = new OleDbDataAdapter();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Customer";
adp.SelectCommand = cmd;
OleDbCommandBuilder ocb = new OleDbCommandBuilder(adp);
conn.Open();
DataSet ds = new DataSet();
string sTabell = "Customer";
adp.Fill(ds, sTabell);
DataTable dt = ds.Tables[sTabell];
DataRow dr = dt.NewRow();
dr["Number"] = 111;
dr["Name"] = "Acme Inc";
dr["Phone"] = "12345";
dt.Rows.Add(dr);
dt.AcceptChanges();
adp.UpdateCommand = ocb.GetUpdateCommand();
adp.Update(ds, sTabell);
conn.Close();
The code below is working all the way. The problem is that the Update method
of the adapter doesn't update the mdb database. What am I doing wrong,
anyone?
string path = Path.GetDirectoryName(Application.ExecutablePath);
string sConn = @"provider=Microsoft.Jet.OLEDB.4.0;data
source=c:\temp\testxp.mdb";
OleDbConnection conn = new OleDbConnection(sConn);
OleDbDataAdapter adp = new OleDbDataAdapter();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Customer";
adp.SelectCommand = cmd;
OleDbCommandBuilder ocb = new OleDbCommandBuilder(adp);
conn.Open();
DataSet ds = new DataSet();
string sTabell = "Customer";
adp.Fill(ds, sTabell);
DataTable dt = ds.Tables[sTabell];
DataRow dr = dt.NewRow();
dr["Number"] = 111;
dr["Name"] = "Acme Inc";
dr["Phone"] = "12345";
dt.Rows.Add(dr);
dt.AcceptChanges();
adp.UpdateCommand = ocb.GetUpdateCommand();
adp.Update(ds, sTabell);
conn.Close();