Hi all,
I'm having a problem updating a simple change I've made to a Access 2000
table through databinding. The error I get is :
An unhandled exception of type 'System.InvalidOperationException'
occurred in system.data.dll
Additional information: Update requires a valid InsertCommand when
passed DataRow collection with
new rows.
The relevant code used is below :
public DataSet MakeConnection()
{
string source = @"Provider=Microsoft.Jet.OLEDB.4.0;"+@"Data Source=A:\
ClientInfo.mdb;";
string select = "SELECT * FROM ClientInfo";
OleDbConnection conn = new OleDbConnection(source);
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(select, conn);
this.dax = da;
*dax is a class level variable.
DataSet ds = new DataSet();
da.Fill(ds, "ClientInfo");
return ds;
}
private void btnNew_Click(object sender, System.EventArgs e)
{
DataRow row = ds.Tables["ClientInfo"].NewRow();
//row.BeginEdit();
*Have tried this line but still no joy.
row["Address1"] = txtAddress1.Text;
row["Address2"] = txtAddress2.Text;
row["Address3"] = txtAddress3.Text;
row["Address4"] = txtAddress4.Text;
ds.Tables["ClientInfo"].Rows.Add(row);
//row.EndEdit();
*Have tried this line but still no joy.
DataSet dsNew = ds.GetChanges(DataRowState.Added);
da.Update(dsNew, "ClientInfo");
*This is the line where the error (above) occurs!!!
ds.AcceptChanges();
}
I guess it's simple but I can't figure it out, please help???????
Thanks, Jon.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200506/1