plot

plot

  • NA
  • 8
  • 0

DataAdapter Update Method

Sep 15 2004 6:28 AM
Hi Guys I'm trying to use the Update method of my DataAdapter. As i understnad it, i fill a dataset with my DataAdapter, make the changes to my Dataset, then i can call the update method of the DataAdapter and .Net will determin the changes and perform the update. I get an exception asking for an update or insert command object for the DataAdapter. Surley if i have to write my own Commands for updates and Inserts etc the Update method of the DataAdapter is pointless? Here is the code: string ConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=C:\\C#\\db.mdb"; OleDbConnection conn = new OleDbConnection(ConnString); OleDbCommand cmd = new OleDbCommand("SELECT * FROM tblData", conn); OleDbDataAdapter adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; DataSet ds = new DataSet(); DataTable dt = new DataTable("tbl"); ds.Tables.Add(dt); try { conn.Open(); adapter.Fill(ds.Tables["tbl"]); } catch(System.Data.OleDb.OleDbException ex) { Console.WriteLine(ex.Message); } catch(Exception exx) { Console.WriteLine(exx.Message); } finally { conn.Close(); } System.Data.DataRow NewRow = ds.Tables["tbl"].NewRow(); NewRow["dbName"] = "Peter"; NewRow["dbAge"] = 25; ds.Tables["tbl"].Rows.Add(NewRow); adapter.Update(dt); Console.WriteLine("Update Successful"); Any help would be much appriceated. Thanks Guys Chris

Answers (4)