PrimaryKey Acces

N

news.kuleuven.be

I create a dataAdapter for Table in Access
-----
daTracks.SelectCommand.CommandText = "SELECT * FROM Tracks"
daTracks.FillSchema(DS, SchemaType.Source, "Tracks")
-----
In Acces the table has a primarykey 'ID' set to autoincrement
---
Dim myDataRow As DataRow = DS.Tables("Tracks").NewRow
myDataRow("Path") = nTrackPath
myDataRow("Track") = mTrack
DS.Tables("Tracks").Rows.Add(myDataRow)
Dim mTrackID = myDataRow("ID")
----
When adding a new datarow to the table in the dataset and asking for the ID,
i always get 0 as first ID (mTrackID = 0)
---
daTracks.Update(DS, "Tracks")
---
but when i update the table in access using the dataataper.update this new
created row gets ID = 1 in Access ?

Another problem:
after inserting 100 rows in the Access Table. I delete in Access the last
record in the table.

When adding a new datarow through the dataAdapter it gets ID 100 like it
shoud, but when the Access Table is update the ID is changed to 101 ?

How Come ?
 
G

Guest

Hi,

The autonumber datatype is just what it says auto numbering. It can
generate three types of numbers for you. Sequential numbers (the default)
which increment by 1, Random numbers, and GUID (for replication). Once the
number has been generated you cannot change or delete it which means you
cannot do inserts or updates to this field. If you delete a row the next
number generated will be the next number in its sequence (e.g. delete the
last row which is ID=100 the next in sequence is 101…that is if it is a
sequential type). If you need this kind of functionality I would suggest
that you create your own sequence generator for the id in code and change the
autonumber field to a number.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top