Access DB - Autonumbers?

J

Julie Smith

Hi,
I have a question about autonumbers in Access db. How are they assigned when
adding a new row to a table?

I have table that has an autonumber column (replication ID/System.Guid) and
a name column. When making a new row, I assign the name, then add the row to
the table. I would have thought that the autonumber would be automatically
given, but this does not seem to be the case.

Can anyone help me?

Thank you in advance.
 
S

sloan

In Access 2000.

I created a User table.

UserUUID = AutoNumber, ReplicationID ( indexed no duplicates)
LoginName = Text 50 (default)

When I do this, and add a new row, I get a fresh guid in the UserUUID
column.

How are you adding the row? Code?

.........
 
J

Julie Smith

Keeping in mind I have added the access db to vs.net and it has generated
tableadapters and the dataset for me. I have UserDataSet as the dataset,
with one table, Users (<pk>ID, name). Where ID is the replicationID
autonumber and name is a string (20 in size, not that it matters).

UserDataSet udataset = new UserDataSet();
UserDataSet.UsersRow ur = udataset.Users.NewUsersRow();
ur.name = "Julie";
udataset.Users.AddUsersRow(ur);

The last line of the code above throws a null exception because the ID
column has not been set. As I said in my previous post, I would have thought
the autonumber, ID, would have automatically provided.

How can I overcome this exception throw and add this row to the table?
 
S

sloan

Why don't you just specify one?

ur.ID = System.Guid.NewGuid();

Try that. (Not proven, just a guess)
 

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