Using UPDATE I con't write the dataset back to datasource

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

It works fine with the datagrid but with the sqlAdapter. Here is the code I
was using. if State is always undefined. so it skips the logic, but the
Textboxes hold the changed information. I am learning, please advise. Thanks
 
Oops! I forgot to attach the code.


private void btnSave_Click(object sender, System.EventArgs e)
{
try
{

DataSet changedData = customerDataSet1.GetChanges();
if (changedData != null)
{
// customerDataSet1.Tables["tblCustomer"].Rows[0]["CarNo"] = textBox1.Text;
//customerDataSet1.Tables["tblCustomer"].Rows[0]["Name"] = textBox2.Text;
sqlDataAdapter1.Update(customerDataSet1);
MessageBox.Show("Database updated!");
customerDataSet1.AcceptChanges();
}
else
{
MessageBox.Show("Nothing to save", "No changes");
}
}
catch(Exception ex)
{
MessageBox.Show("An error occurred updating the database:"+"ex.Message",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
customerDataSet1.RejectChanges();
}
}
 
BJ,

Probably you miss (when you are using the datagrid) the endcurrentedit which
you can place as first instruction in in your btnSaveClick event.

Here is the command with an untyped dataset where the dataset name is ds.

BindingContext(ds.Tables(0)).EndCurrentEdit()

(The command pushes donw a row from a datagrid in its datasource, what is
normaly automaticly done by a rowchange on the datagrid)

Decide yourself if you keep this untyped one or want to use the typed names.

I hope this helps,

Cor
 
Thanks that didn't work, but you put me on the right track.
customerDataSet1.tablename.Rows[0].EndInit.

don't ask me why but it solved my problem. What I realy wanted was that it
automatically figures out all the rows that I modified and updates them. That
is how it is supposed to do!

Thanks again
 
What I realy wanted was that it
automatically figures out all the rows that I modified and updates them.
That
is how it is supposed to do!
If (ds.HasChanges) {
da.Update(ds.GetChanges);
da.AcceptChanges;}

Normally in in an Update the Acceptchanges is not needed, that is build in.
However the GetCatChanges is a copy of the dataset.

I hope this helps,

Cor
 
Back
Top