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

C# Datagrid update problem

P: n/a
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

Jun 14 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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


Jun 14 '06 #2

P: n/a
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:

Jun 14 '06 #3

P: n/a
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]" <ga****@gmail.com>
???????:11*********************@y41g2000cwy.google groups.com...
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

Jun 15 '06 #4

P: n/a
I have the

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

And now the Delete is working fine.
"Jason Huang" <Ja************@hotmail.com> glsD:ep**************@TK2MSFTNGP05.phx.g bl...
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]" <ga****@gmail.com>
???????:11*********************@y41g2000cwy.google groups.com...
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


Jun 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.