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!

Cannot commit changes to dataset 1

Status
Not open for further replies.

fsteeman

Programmer
Jul 17, 2002
103
DK
Hello all,

I have been working on a relatively straightforward routine to migrate data from one database to another. VB.NET is pretty new to me; I have previously been working with VB6.

I get the routine to read the rows in the source database (srcRow collection) and generate new rows in the target database (trgRow collection) putting the data in the appropriate data fields. Everything seems to go well, except for the fact that the data I pull is not saved in the target database! Here you see an excerpt of the routine:

[navy]
[green]'Iterate source rows[/green]
For Each srcRow In Me.GMDBDataSet.TBL_Mastertable.Rows
[green]'generate new row in target db[/green]
trgRow = Me.GMDB2DataSet.Master.NewMasterRow()
[green]'enter 1 (MMH prefix) in InstitutionCode[/green]
trgRow("InstitutionCode") = 1
[green]'enter 1 (TS prefix) in CollectionCode[/green]
trgRow("CollectionCode") = 1
[green]'copy specimennumber to CatalogNumber[/green]
trgRow("CatalogNumber") = srcRow.Item("SpecimenNumber")
[/navy]
*snip*
[navy]
Next srcRow

MasterBindingSource.EndEdit()
Me.GMDB2DataSet.Master.AcceptChanges()
Me.MasterTableAdapter.Update(Me.GMDB2DataSet.Master)

Console.WriteLine("Done!")
Console.WriteLine("")

[green]'test[/green]
For Each srcRow In Me.GMDB2DataSet.Master.Rows
Console.WriteLine(srcRow.Item("CatalogNumber") & ": " & srcRow.Item("ScientificName"))
Next

[/navy]

The test at the bottom yields no output whatsoever! What did I do wrong!?

Thanks in advance for any help...

Fedor
 
probably something like this

Me.GMDB2DataSet.Master.rows.add(trgrow)

somewhere before next srcrow

Did you use the wizard to make your Dataset? or did you make the strongly typed dataset yourself?

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Thanks. I will try that.

I already tried adding [navy]trgRow.AcceptChanges()[/navy] to the end of the iteration, but I get a RowNotInTableException. So apparantly, the row is not part of the table I want to change, which is strange, because I have clearly equalled it with a new row in the target datatable (Master)...

And yes, I did everything with wizards in Visual Basic 2005 Express (Edition Beta), because I know not better... :-(

Fedor
 
Thanks a million! That did the trick! It also actually sense after all. The trgRow was simply not belonging to the table...
 
yes you have equalled it with a new row wich means the row will be of the same structure as the datatable. All the same fields from the same types. But it still needs to be added to the table.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Which brings me to the next problem I am struggling with... :-(

Apparantly, the new rows are still not saved in the actual database. When I open the database itself I can see that the rows that are so neatly reproduced in my test-loop aren't there at all! Now I know that .NET keeps whole copies of datasets and tables in memory while working with it (disconnected access). But then a few simple commands should suffice to update the target database, like you can see in the example above. Are there any commands that I missed?
 
No? I didn't think so either (that I missed anything)... Yet, I still have no idea why my changes are not committed to the database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top