Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > autoincrement seed set to -1 updates db to this value
 

autoincrement seed set to -1 updates db to this value

vb 2005

hi,
im read somewhere that using strongly typed datasets, you should set the PK to autoincrement but in negative numbers so that it doesn't clash with the autonumbers generated by the database.

in my case, im using MySQL and strongly typed datasets. the UserID column in the database is set to autoincrement. on my typed dataset i have that column set to autoincrement but in negative numbers.

now, i have a form where i would like to present the user with a textbox bound to the UserID column. so i databind it to the UserID column.

my problem is, when i create a new row, the textbox shows a number like -1. worse is that when i persist to database, the value -1 gets stored instead of the normal autoincrement. i would like to know if there's a way to have the UserID dataset column not persist in the database even though its bound. i need it to be bound because i want to extract the value in the database and present that to the user, but i dont want to persist a negative number. how would i go about this?

newyuppie  Thursday, September 28, 2006 3:05 AM

Hi,

What value you are trying to assign to textbox after loading the form? Is the value -1 coming from database or from typed dataset?

Thank you,
Bhanu.

Bhanu Prakash Nunna - MSFT  Thursday, September 28, 2006 10:10 PM
well its happening on empty database. my typed dataset has the id column seed to -1, but the textbox that presents this to the user is bound to the id column from the bindingsource (thus, -1). when i update the database with the changes, database stores the -1 instead of assigning the column its own autonumber id.
btw im using MySQL

thanks
newyuppie  Saturday, September 30, 2006 1:35 AM

You can use google to search for other answers

Custom Search

More Threads

• .NET exe
• Child Forms All show the same row.
• Checkbox + datagrid
• Yet another Data binding question, my control doesnt update the datasource.
• CheckedListBox Not Displaying
• BindingSource
• DataGridView slow refresh
• Multi-Font DataGridViewComboBoxCell
• Datagridview RowLeave Exceptions
• Using a "in" statement in a dataset/dataadapter