By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,967 Members | 815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,967 IT Pros & Developers. It's quick & easy.

Update requires a valid InsertCommand when passed DataRow collection

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
It's simple but please help!

Jon S wrote:
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
Nov 17 '05 #2

P: n/a
Hi Jon,

The data adapter needs to know the way to insert the added data row to the
Access data table. You basically have two options here: you can either
create an appropriate OleDbCommand in code and assign a reference to this
command to the adapter's InsertCommand, or you can instantiate the
OleDbCommandBuilder class which will generate the insert command for you.
Please refer to MSDN docs on the OleDbCommandBuilder class for the specific
requirements of its usage.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Jon S via DotNetMonster.com" <fo***@nospam.DotNetMonster.com> wrote in
message news:50***********@DotNetMonster.com...
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


Nov 17 '05 #3

P: n/a
Hi Dmytro

Thanks for that. I shall read up on it.

Thanks.

Dmytro Lapshyn [MVP] wrote:
Hi Jon,

The data adapter needs to know the way to insert the added data row to the
Access data table. You basically have two options here: you can either
create an appropriate OleDbCommand in code and assign a reference to this
command to the adapter's InsertCommand, or you can instantiate the
OleDbCommandBuilder class which will generate the insert command for you.
Please refer to MSDN docs on the OleDbCommandBuilder class for the specific
requirements of its usage.
Hi all,

[quoted text clipped - 42 lines]
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
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.