C# Datagrid update problem

J

Jason Huang

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
 
G

Galcho[MCSD.NET]

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
 
J

Jason Huang

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 said:
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 said:
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
 
J

Jason Huang

I have the

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

And now the Delete is working fine.


Jason Huang said:
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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top