[2.0] Update requires a valid InsertCommand when passed DataRow collection with new r
why this code doesnt work?
Code:
string ConStr = "Provider=Microsoft.Jet.OleDB.4.0; Data Source =" + Application.StartupPath + "\\Employee.mdb";
OleDbConnection Conn = new OleDbConnection(ConStr);
Conn.Open();
OleDbCommand Cmd = new OleDbCommand("Select * from Employee", Conn);
OleDbDataAdapter dAdapter = new OleDbDataAdapter(Cmd);
DataSet dDataSet = new DataSet();
dAdapter.Fill(dDataSet, "Employee");
DataRow AddNewRow = dDataSet.Tables["Employee"].NewRow();
AddNewRow["EmployeeID"] = textBox1.Text;
AddNewRow["EmployeeName"] = textBox2.Text;
dDataSet.Tables["Employee"].Rows.Add(AddNewRow);
dAdapter.Update(dDataSet, "Employee");
Conn.Close();
the error is:
"Update requires a valid InsertCommand when passed DataRow collection with new rows"
Re: [2.0] Update requires a valid InsertCommand when passed DataRow collection with new r
You can't insert a record into a database table without SQL code. That SQL code needs to be contained in the InsertCommand of your DataAdapter. Likewise the DeleteCommand and UpdateCommand control how records get deleted and updated. You need to create the Command yourself or else use an OleDbCommandBuilder.