Question Data Binding & Autoincrement primary Key

kbutchm

Member
Joined
May 12, 2011
Messages
10
Programming Experience
1-3
Hi,

I'm developing a small database using vb.net and MS SQL Server in MS Visual Studio. I developed a data source from the database and dragged a table onto a form in the project using the Data Binding Technique (all code was automatically generated).
My problem is that I'm unable to auto-increment my primary key on my form.
When I click 'add new' on the navigator toolbar on the top, the ID textbox (which holds the primary key), stays empty, as no number enters the textbox, not even -1 as I have seen on other example databases. Therefore I'm not able to save information.
When I add data manually to the database, it increments fine as I have set these properties in the database:
  • Identity Spec = yes
  • Is Identity = yes
  • Identity Increment = 1
  • identity seed = 1
Am I leaving something out? Any help would be appreciated.
Thanks in advance
 
If you try to save data, does it fail?

You should examine the properties for that column in your DataSet. Open the DataSet in the designer, select that column and open the Properties window. Is AutoIncrement (I think that's what it's called) property set to True?

It does seem strange that you get no value because, even it's not auto-incremented, the default value should be zero it the type is Integer or some other numeric type. It might be worth your while checking the bindings for that TextBox.

That said, you probably shouldn't be displaying an auto-incremented primary key to the user anyway.
 
Thanks for that! I had the Auto_Increment property set to false on my ID key and when it was set to True, it solved the problem.
Again, thanks for your help.
 
Back
Top