Question Easy DataSet/DataGridView question

evanbooth

New member
Joined
Mar 17, 2009
Messages
3
Programming Experience
5-10
Hey guys,

I have a table that has an auto-incrementing primary key. I'd like to manually add new rows to a dataset (that consequently show up on a datagridview) and be able to commit these new lines in the future.

When I try to add a new row, I get an error that my primary key column can't be set to null. That makes perfect sense, but I can't very well get the primary key without actually adding the row to the table.


Does that make any sense?



Thanks!
 
In your dataset table you want to set the auto-incrementing propeteries so that there generating negative numbers. It will update to the proper keys once you call your dataadapter.update statement on the table.

AutoIncrement = True
AutoIncrementSeed = -1
AutoIncrementStep = -1

Also in the design environment create a new or open an existing typed dataset. Open the Server Explorer and connect to your database, then drag and drop the table you want into the dataset. You will see that in the dataset it will automatically set those properties on your identity seed column to auto increment in negative numbers.
 
Last edited:
check also that the tableadapter (right click it and choose configure) has the advanced option of REFRESH THE DATASET ticked. That way when you update the client rows into the sql server db, the PK id value that the DB calculates will be populated back into the dataset automatically
 
Back
Top