How to insert a new row to MDB file [modified]
-
First of all, i wrote execly the same Subject yesterday but i didnt understand the answer.. :( i want to add a new row to specific MDB file... my code is:
string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Dir;
string commandString = "Select id,Event from Events";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "Events");DataTable datatable = ds.Tables[0];
DataRow newRow = datatable.NewRow();
newRow["id"] = "aaa";
newRow["Event"] = "bbb";datatable.Rows.Add(newRow);
dataAdapter.Update(ds, "Events");
ds.AcceptChanges();
Application.DoEvents();i did this code but it pop a exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows" What i need t do? and where? thank you very Much G.
modified on Thursday, July 31, 2008 3:59 AM
-
First of all, i wrote execly the same Subject yesterday but i didnt understand the answer.. :( i want to add a new row to specific MDB file... my code is:
string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Dir;
string commandString = "Select id,Event from Events";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "Events");DataTable datatable = ds.Tables[0];
DataRow newRow = datatable.NewRow();
newRow["id"] = "aaa";
newRow["Event"] = "bbb";datatable.Rows.Add(newRow);
dataAdapter.Update(ds, "Events");
ds.AcceptChanges();
Application.DoEvents();i did this code but it pop a exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows" What i need t do? and where? thank you very Much G.
modified on Thursday, July 31, 2008 3:59 AM
Admin887 wrote:
i did this code but it pop a exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows" What i need t do? and where?
You need to provide an insert command. Read some of the documentation to understand how it works.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
First of all, i wrote execly the same Subject yesterday but i didnt understand the answer.. :( i want to add a new row to specific MDB file... my code is:
string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Dir;
string commandString = "Select id,Event from Events";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "Events");DataTable datatable = ds.Tables[0];
DataRow newRow = datatable.NewRow();
newRow["id"] = "aaa";
newRow["Event"] = "bbb";datatable.Rows.Add(newRow);
dataAdapter.Update(ds, "Events");
ds.AcceptChanges();
Application.DoEvents();i did this code but it pop a exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows" What i need t do? and where? thank you very Much G.
modified on Thursday, July 31, 2008 3:59 AM