PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 1.33 average.

Update requires a valid InsertCommand when passed DataRow collection

 
 
Jon S via DotNetMonster.com
Guest
Posts: n/a
 
      22nd Jun 2005
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
 
Reply With Quote
 
 
 
 
Jon S via DotNetMonster.com
Guest
Posts: n/a
 
      22nd Jun 2005
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
 
Reply With Quote
 
 
 
 
Dmytro Lapshyn [MVP]
Guest
Posts: n/a
 
      22nd Jun 2005
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" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Jon S via DotNetMonster.com
Guest
Posts: n/a
 
      23rd Jun 2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Message :-Update requires a valid InsertCommand when passed DataRow collection with new rows. aviralsaxena08 Webmaster / Programming 0 10th Apr 2012 10:28 AM
Is DataRow[string] uses DataRow[int] and DataRow[int] much efficient than DataRow[string]? Ryan Liu Microsoft C# .NET 3 2nd Feb 2008 07:14 AM
Distinguish 2 situations when a DataRow in Detached state; Or why not make the data row intact after being added then removed from a dataRow collection? Ryan Liu Microsoft Dot NET 0 7th Jun 2006 03:04 PM
Update Requires a valid insertcommand when passed datarow collection with new rows Roy Microsoft ADO .NET 1 10th Nov 2003 09:44 PM
HELP-Update requires a valid updatecommand when passed datarow collection with modified rows =?ISO-8859-1?Q?Wulf_Br=F6kel?= Microsoft ADO .NET 0 23rd Sep 2003 10:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:58 PM.