Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No updating of database during debugging? 1

Status
Not open for further replies.

fsteeman

Programmer
Jul 17, 2002
103
DK
Does anybody know whether VB 2005 Express inhibits the updating of a database during debugging? I have written a routine I am trying out, but it adds or changes no record to the target database.

If so, all I need to do is compile to make it work. If not, then there are some method calls I probably forgot...



Fedor Steeman
Geological Museum Copenhagen
Denmark
 
Could you show the code in question?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Here is the code:

[navy]
For Each srcRow In Me.GMDBDataSet.TBL_Mastertable.Rows
trgRow = Me.GMDB2DataSet.Master.NewMasterRow()
trgRow("InstitutionCode") = 1
trgRow("CollectionCode") = 1
trgRow("CatalogNumber") = srcRow.Item("SpecimenNumber")
[/navy]
*snipped out section with a lot of changes to a lot of tables*
[navy]
[green]'trgRow.Acceptchanges[/green]
Me.GMDB2DataSet.Master.Rows.Add(trgRow)

Next srcRow

[green]'MasterBindingSource.EndEdit()[/green]
Me.GMDB2DataSet.Master.AcceptChanges()
Me.GMDB2DataSet.HigherTaxa.AcceptChanges()
Me.GMDB2DataSet.Genera.AcceptChanges()
Me.GMDB2DataSet.Species.AcceptChanges()
Me.GMDB2DataSet.Localities.AcceptChanges()
Me.GMDB2DataSet.Stratigraphy.AcceptChanges()
Me.GMDB2DataSet.References.AcceptChanges()
Me.GMDB2DataSet.Persons.AcceptChanges()

Me.MasterTableAdapter.Update(Me.GMDB2DataSet.Master)
Me.HigherTaxaTableAdapter.Update(Me.GMDB2DataSet.HigherTaxa)
Me.GeneraTableAdapter.Update(Me.GMDB2DataSet.Genera)
Me.SpeciesTableAdapter.Update(Me.GMDB2DataSet.Species)
Me.LocalitiesTableAdapter.Update(Me.GMDB2DataSet.Localities)
Me.StratigraphyTableAdapter1.Update(Me.GMDB2DataSet.Stratigraphy)
Me.ReferencesTableAdapter.Update(Me.GMDB2DataSet.References)
Me.PersonsTableAdapter.Update(Me.GMDB2DataSet.Persons)
[/navy]

Fedor Steeman
Geological Museum Copenhagen
Denmark
 
Here's the problem:

Me.GMDB2DataSet.Master.AcceptChanges()
Me.GMDB2DataSet.HigherTaxa.AcceptChanges()
Me.GMDB2DataSet.Genera.AcceptChanges()
Me.GMDB2DataSet.Species.AcceptChanges()
Me.GMDB2DataSet.Localities.AcceptChanges()
Me.GMDB2DataSet.Stratigraphy.AcceptChanges()
Me.GMDB2DataSet.References.AcceptChanges()
Me.GMDB2DataSet.Persons.AcceptChanges()

When you tell the DataSet to AcceptChanges, it does just that - accepts the changes and resets whatever flag it uses to indicated that there are currently no changes to the DataSet. So, when you call Update after calling AcceptChanges, the DataSet indicates that there is nothing to Update, so no Update is performed.

Here's what MSDN says about AcceptChanges:

Both the DataRow and DataTable classes also have AcceptChanges methods. Calling AcceptChanges at the DataTable level causes the AcceptChanges method for each DataRow to be called. Similarly, invoking AcceptChanges on the DataSet causes AcceptChanges to be called on each table within the DataSet. In this manner, you have multiple levels at which the method can be invoked. Calling the AcceptChanges of the DataSet enables you to invoke the method on all subordinate objects (for example, tables and rows) with one call.

When you call AcceptChanges on the DataSet, any DataRow objects still in edit-mode successfully end their edits. The RowState property of each DataRow also changes; Added and Modified rows become Unchanged, and Deleted rows are removed.

If the DataSet contains ForeignKeyConstraint objects, invoking the AcceptChanges method also causes the AcceptRejectRule to be enforced.

So, either remove the AcceptChanges calls, or move them to after the Update calls.

Also, I believe that calling Update automatically calls AcceptChanges, but I'm not sure.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Oh, and by the way, I very briefly visited Copenhagen in 1987, and think it is a beautiful city. I'd like to come back sometime. I'll try to visit your museum if I ever make it back!


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Of course! It is so logical now that you explained it to me. Because I wasn't getting any results I was using a 'spreadfire', i.e. using whatever method that seemed to apply to getting the thing to do what I want. I better just remove AcceptChanges...

Thank you so much for your very clear explanation!

BTW you are welcome to vist! Although the Geological Museum isn't all that big or special, it is right across the Art Museum, so it could merit a short stopping by. :)

Fedor Steeman
Geological Museum Copenhagen
Denmark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top