473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Update requires a valid InsertCommand when passed DataRow collection

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
3 21342
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Yog | last post by:
I have a datagrid binded to a dataset and once the user updates the grid my dataset is reflected. When i wanted to save the data to tables, however i needed to insert this data into another...
2
by: Mojtaba Faridzad | last post by:
Hi, Please check these lines: DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, "mytable"); DataRow row; row = dataSet.Tables.Rows; row.BeginEdit(); row = "555";
1
by: amessimon | last post by:
Hi I have a problem with an insert statment using the update() method of the OledbDataAdapter. I'm getting the error 'Update requires a valid InsertCommand when passed DataRow collection with...
6
by: Wanda | last post by:
Hello, I tried to update a row in a table by using the datarow and data adapter. Unfortunately, it doesn't update. I try finding that datarow and set it to "dr", I can see dr could be just an...
1
by: Moomin Ma | last post by:
I have create a excel file with 2 columns and 2 rows for demonstration. The excel file is then opened by ms access and therefore a mdb file was created. The mdb file showing the correct linkage...
1
by: N! Xau | last post by:
Hi all, I created a dataform using the wizard, everything works fine. I set both grids to readonly = true, and added a button to switch this property and save modifications to db. I didn't make...
1
by: Shaun O''Callaghan | last post by:
Hi All, I have a typed dataset on a Windows form on Smart Device Application that displays data from a Sql Server Mobile database. The problem is, whenever I want to add a new record I first...
1
by: Tim Kelley | last post by:
I need to loop through a datatable and update a particular field. This seems like it should be fairly easy but it is giving me fits. Here is the code that I have so far. foreach (DataRow row...
3
by: =?Utf-8?B?TXJrIEJsYWNrYWxs?= | last post by:
Hi all, This is my first attempt to update an access database in VB.Net 2005. It goes broadly as follows (I have condensed it): Dim MyConnection As New Data.OleDb.OleDbConnection...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.