1
votes

I am doing a small project to learn how to use DataSet but i have a small problem. Consider following code:

foreach (DatabaseDataSet.ApplicationRow rowApplication in database.Application)
{
      if (rowApplication.AID.ToString() == lblIDApplication.Text)
      {
            rowApplication.Date= tbApplicationDatum.Text;
            rowApplication.Status = tbApplicationStatus.Text;                
            applicationAdapter.Update(rowApplication);    
            break;
      }

}

I don't know why but the database doesn't get updated. The DataRow is being updated as when I call the data again I see the new value. But when I re-run my application it's back to it's old value again. Any help?

EDIT: I'm working with strongly typed DataSet

3
Depending on how you're using the DataSet you may need to look into this: Updating Data Sources with DataAdapters.Magnus Grindal Bakken
Try adding rowApplication.BeginEdit() and rowApplication.EndEdit()svenv
this also doesn't work :(LeonidasFett
When I execute the Update() Method, I see that the DataSet database is being updated as it contains the new value. But somehow it doesn't get written to the database...LeonidasFett

3 Answers

3
votes

You need to call the Update method of your adapter to propogate the changes

AcceptChanges only updates the changes in memory for the row and does not migrate those to the database

MSDN AcceptChanges and RejectChanges only apply to DataRow related changes (that is, Add, Remove, Delete, and Modify). They are not applicable to schema or structural changes.

Calling AcceptChanges will not replicate these changes back to the data source if the DataSet was filled using a DataAdapter. In that situation, call Update instead See Updating Data Sources with DataAdapters for more information

2
votes

Its important to remember that the DataSet is a 'local copy' of the data not a 'live link' to the DB. If your DataSet is populated by a IDataAdaptor (say a TableAdaptor) for example you need to call the DataAdaptors Update method passing in the Updated dataset to sync the results back to the underlying DB.

Also I would suspect you DONT want to be doing 'new ApplicationTableAdapter()' because typically you would want to update with the TableAdaptor you populated with, at the least you would need to ensure you had the correct connection, query etc set up.

1
votes

SOLUTION: It happens that nothing was wrong with the code. I had two ConnectionString defined in App.config. I forgot to remove the first one after I removed a previous database that had errors in it. Upon removing the first ConnectionString, everything worked.