Now here is something special:
I discovered that when generating new rows in a VB.NET application, the autonumbering starts with 0, whereas in the database itself, MS Access, it starts with 1. This is rather annoying as I am working on a routine to move and normalize data from one database to another. Whenever I write the foreign key in one table, in Access the primary key in the referred table is incremented by one!
For example:
[navy] [green]
'*Normalize Genus to Genera[/green]
If srcRow.Item("Genus").ToString() <> "" Then
[green]'locate entry in Genera-table (on name)[/green]
fndRows = Me.GMDB2DataSet.Genera.Select("GenusName = '" & srcRow.Item("Genus").ToString & "'")
[green]'if not found then add new record, copy Genus to Genera:GenusName, copy HigherTaxa reference to Genera
arentTaxon[/green]
If fndRows.Length = 0 Then
nrmRow = Me.GMDB2DataSet.Genera.NewGeneraRow
nrmRow.Item("GenusName") = srcRow.Item("Genus")
nrmRow.Item("ParentTaxon") = hitaxon
nrmRow.Item("ParentGenus") = 0
Me.GMDB2DataSet.Genera.Rows.Add(nrmRow)
[green]'remember genus foreign key[/green]
genus = nrmRow.Item("genus_ID")
Else
[green]'entry found, remember genus foreign key[/green]
genus = fndRows(0).Item("genus_ID")
End If
Else
genus = 0
End If
[/navy]
Of course there is a simple ad-hoc solution to this by simply adding 1 to the foreign key that needs to be entered in another table:
[navy]genus = fndRows(0).Item("genus_ID")[red] + 1[/red][/navy]
However, it is very strange that ADO.NET does not apply the same rules as the source database.
Fedor Steeman
Geological Museum Copenhagen
Denmark
I discovered that when generating new rows in a VB.NET application, the autonumbering starts with 0, whereas in the database itself, MS Access, it starts with 1. This is rather annoying as I am working on a routine to move and normalize data from one database to another. Whenever I write the foreign key in one table, in Access the primary key in the referred table is incremented by one!
For example:
[navy] [green]
'*Normalize Genus to Genera[/green]
If srcRow.Item("Genus").ToString() <> "" Then
[green]'locate entry in Genera-table (on name)[/green]
fndRows = Me.GMDB2DataSet.Genera.Select("GenusName = '" & srcRow.Item("Genus").ToString & "'")
[green]'if not found then add new record, copy Genus to Genera:GenusName, copy HigherTaxa reference to Genera
If fndRows.Length = 0 Then
nrmRow = Me.GMDB2DataSet.Genera.NewGeneraRow
nrmRow.Item("GenusName") = srcRow.Item("Genus")
nrmRow.Item("ParentTaxon") = hitaxon
nrmRow.Item("ParentGenus") = 0
Me.GMDB2DataSet.Genera.Rows.Add(nrmRow)
[green]'remember genus foreign key[/green]
genus = nrmRow.Item("genus_ID")
Else
[green]'entry found, remember genus foreign key[/green]
genus = fndRows(0).Item("genus_ID")
End If
Else
genus = 0
End If
[/navy]
Of course there is a simple ad-hoc solution to this by simply adding 1 to the foreign key that needs to be entered in another table:
[navy]genus = fndRows(0).Item("genus_ID")[red] + 1[/red][/navy]
However, it is very strange that ADO.NET does not apply the same rules as the source database.
Fedor Steeman
Geological Museum Copenhagen
Denmark