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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autonumber field is zero after addnew

Status
Not open for further replies.

custsoft

Programmer
Aug 29, 2000
41
I have an access database that I am adding data to with a dataadapter and dataset with the following code:
Me.DstOwnerInfo1.Clear()
Me.oledb_adaptOwnerInfo.SelectCommand.Parameters ("ownerid").Value = 0
Me.oledb_adaptOwnerInfo.Fill(Me.DstOwnerInfo1)
OwnerBindingManager = Me.BindingContext(DstOwnerInfo1, "graveownerinfo")
OwnerBindingManager.AddNew()
OwnerBindingManager.EndCurrentEdit()
Me.oledb_adaptOwnerInfo.Update(DstOwnerInfo1)

The ownerid field is an autonumber field.
It adds the record correctly to the datagrid and database with the correct autonumber in the ownerid field.
But when I try to access the ownerid field in the dataset it always shows zero.
How do I get the added autonumber field?
Do I have to write code to requery the added row and get the ID etc
One more question, I am filling my dataset by querying on a zero ownerid, which should not exist. So I assume my dataset is empty and then I do the addnew. Is that a problem or do I have to go to the end of the full database?

Thanks for help in advance.
 
I think that a fillschema will do the trick

Me.oledb_adaptOwnerInfo.Fillschema(Me.DstOwnerInfo1,source)

otherwise you will have to set the property of that column

Code:
ds.tables("tablenameorindex").Columns("columnnameorindex").AutoIncrement = True

Christiaan Baes
Belgium

"My new site" - Me
 
Thanks for taking the time to reply, chrissie1. I think you might misunderstand my question. I can get the record to add and it automatically assigns a new consecutive number to the autonumber field. I just can't get the value of that new autonumber. It always shows as zero. I have searched on "autonumber" which does reference a solution using 'select @@identity using an oledbcmd. I couldn't get it to work. May way around it was to requery the database to get the count value. What a waste, but it gets me what I want. Thanks again.
 
ADO.Net by default uses disconnected dataset. That means that the changes you make to a dataset (like adding a row to a table) are stored locally (in memory) until you update the database and refresh the dataset.

I'm not familiar with doing so through bindings, so I can't help you with code there.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top