PC Review


Reply
Thread Tools Rate Thread

C# Datagrid update problem

 
 
Jason Huang
Guest
Posts: n/a
 
      14th Jun 2006
Hi,

In my .Net 1.1 C# winodows form project,
I use the following code trying to update data via a DataGrid.

private void UpdateDataSet(DataSet myDataSet){
if(!myDataSet.HasChanges(DataRowState.Modified)) return;
DataSet xDataSet;
xDataSet = myDataSet.GetChanges(DataRowState.Modified);
if(xDataSet.HasErrors){ }
mySqlDataAdapter.Update(xDataSet);
}

private void btnSave_Click(object sender, System.EventArgs e)
{
this.UpdateDataSet(myGridDS);
}

However, it comes out with an error message saying something wrong with the
modified DataRow and UpdateCommand.
Would someone tell me how to fix it?
Thanks for help.


Jason



 
Reply With Quote
 
 
 
 
Galcho[MCSD.NET]
Guest
Posts: n/a
 
      14th Jun 2006
could you be more specific about exception you get.

why do you exctract changes from datatset? DataAdapater does this for
you as it calls respectively UpdateCommand, Insertcommand and
Deletecommand for each changed, inserted or deleted row.

just call mySqlDataAdapter.Update(myDataSet);

hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

Jason Huang wrote:
> Hi,
>
> In my .Net 1.1 C# winodows form project,
> I use the following code trying to update data via a DataGrid.
>
> private void UpdateDataSet(DataSet myDataSet){
> if(!myDataSet.HasChanges(DataRowState.Modified)) return;
> DataSet xDataSet;
> xDataSet = myDataSet.GetChanges(DataRowState.Modified);
> if(xDataSet.HasErrors){ }
> mySqlDataAdapter.Update(xDataSet);
> }
>
> private void btnSave_Click(object sender, System.EventArgs e)
> {
> this.UpdateDataSet(myGridDS);
> }
>
> However, it comes out with an error message saying something wrong with the
> modified DataRow and UpdateCommand.
> Would someone tell me how to fix it?
> Thanks for help.
>
>
> Jason


 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      14th Jun 2006
Does your DataAdapter actually have live Update, Insert, and Delete commands?

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"unknown" wrote:

>

 
Reply With Quote
 
Jason Huang
Guest
Posts: n/a
 
      15th Jun 2006
Thanks!
I made up the UpdateCommand, InsertCommand, DeleteCommand for
MySqlDataAdapter.
And it worked fine with the Insert and Update.
When I delete a row form the DataGrid, that row will be deleted but it pops
out a message with System.Data.RowNotInTableException.
How do I solve this problem.
Thanks for help.


Jason

"Galcho[MCSD.NET]" <(E-Mail Removed)>
???????:(E-Mail Removed)...
> could you be more specific about exception you get.
>
> why do you exctract changes from datatset? DataAdapater does this for
> you as it calls respectively UpdateCommand, Insertcommand and
> Deletecommand for each changed, inserted or deleted row.
>
> just call mySqlDataAdapter.Update(myDataSet);
>
> hope this helps
> Galin Iliev[MCSD.NET]
> www.galcho.com
>
> Jason Huang wrote:
>> Hi,
>>
>> In my .Net 1.1 C# winodows form project,
>> I use the following code trying to update data via a DataGrid.
>>
>> private void UpdateDataSet(DataSet myDataSet){
>> if(!myDataSet.HasChanges(DataRowState.Modified)) return;
>> DataSet xDataSet;
>> xDataSet = myDataSet.GetChanges(DataRowState.Modified);
>> if(xDataSet.HasErrors){ }
>> mySqlDataAdapter.Update(xDataSet);
>> }
>>
>> private void btnSave_Click(object sender, System.EventArgs e)
>> {
>> this.UpdateDataSet(myGridDS);
>> }
>>
>> However, it comes out with an error message saying something wrong with
>> the
>> modified DataRow and UpdateCommand.
>> Would someone tell me how to fix it?
>> Thanks for help.
>>
>>
>> Jason

>



 
Reply With Quote
 
Jason Huang
Guest
Posts: n/a
 
      16th Jun 2006
I have the

MyTable = myGridDS.Tables[0];
MyTable.AcceptChanges();

And now the Delete is working fine.


"Jason Huang" <(E-Mail Removed)> ¼¶¼g©ó¶l¥ó·s»D:(E-Mail Removed)...
> Thanks!
> I made up the UpdateCommand, InsertCommand, DeleteCommand for
> MySqlDataAdapter.
> And it worked fine with the Insert and Update.
> When I delete a row form the DataGrid, that row will be deleted but it
> pops out a message with System.Data.RowNotInTableException.
> How do I solve this problem.
> Thanks for help.
>
>
> Jason
>
> "Galcho[MCSD.NET]" <(E-Mail Removed)>
> ???????:(E-Mail Removed)...
>> could you be more specific about exception you get.
>>
>> why do you exctract changes from datatset? DataAdapater does this for
>> you as it calls respectively UpdateCommand, Insertcommand and
>> Deletecommand for each changed, inserted or deleted row.
>>
>> just call mySqlDataAdapter.Update(myDataSet);
>>
>> hope this helps
>> Galin Iliev[MCSD.NET]
>> www.galcho.com
>>
>> Jason Huang wrote:
>>> Hi,
>>>
>>> In my .Net 1.1 C# winodows form project,
>>> I use the following code trying to update data via a DataGrid.
>>>
>>> private void UpdateDataSet(DataSet myDataSet){
>>> if(!myDataSet.HasChanges(DataRowState.Modified)) return;
>>> DataSet xDataSet;
>>> xDataSet = myDataSet.GetChanges(DataRowState.Modified);
>>> if(xDataSet.HasErrors){ }
>>> mySqlDataAdapter.Update(xDataSet);
>>> }
>>>
>>> private void btnSave_Click(object sender, System.EventArgs e)
>>> {
>>> this.UpdateDataSet(myGridDS);
>>> }
>>>
>>> However, it comes out with an error message saying something wrong with
>>> the
>>> modified DataRow and UpdateCommand.
>>> Would someone tell me how to fix it?
>>> Thanks for help.
>>>
>>>
>>> Jason

>>

>
>



 
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
Re: Big DataGrid Update Problem-MVP Help Please???? steroche Microsoft ASP .NET 0 25th Aug 2005 07:13 PM
Datagrid Update problem Brett Microsoft Dot NET 10 15th Mar 2005 05:05 PM
datagrid update problem Cyrus Microsoft Dot NET Framework Forms 0 8th Dec 2003 03:06 AM
datagrid update problem Reney Microsoft ADO .NET 0 8th Sep 2003 01:53 PM
Datagrid Update Problem Reney Microsoft VB .NET 4 8th Sep 2003 12:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 AM.