DataGridView and Autonumber

Hey guys,

I noticed that each time I insert a record in the DataGridView, I must fill out the ID column (primary key) as well. I have it set to autonumber in Access, and when I fill in data some other way it works, however in the DGView I have to fill it out manually or it will throw an Exception. Any Ideas

Thanks!




Answer this question

DataGridView and Autonumber

  • LeeroyB

    No, I'm using access. I'm not trying to retrieve anything. When I insert a row right into a DataGridView (it allows insertion, updating and deletion) I have to manually type the next ID (primary key) in instead of the autonumber doing it for me. I'm not submitting a form, I'm actually inserting the values straight into the datagrid.

    Any ideas

    Thanks!

  • Chris Langsenkamp

    Hi

    Check that the primary key Column AutoIncrement property is set to true.
    Like

    dgV.Columns["PK_ColumnName"].AutoIncrement = true;

    Thanks



  • foobarX

    Anybody
  • Harry Hunt

    What happens when you leave it blank

  • Nick Gravelyn

    Hi,

    Are you having problems retrieving the last auto generated number try using the @@identity variable to retrive it.

    SELECT @@IDENTITY AS ident

     

    cheers,

    Paul June A. Domag



  • Loki70

    try the following code on form load event

    dataset.tablename.fieldname.autoincrement=true.



  • Maurice Reeves

    I have this problem as well.....bummer...did you get an answer



  • mteverest

    if i got your problem

    i m giving you over view try to this

    Dim snoColumn As New DataColumn

    snoColumn.AutoIncrement = True

    snoColumn.ColumnName = "sno"

    snoColumn.DataType = System.Type.GetType("System.Int32")

    snoColumn.AutoIncrementSeed =0

    snoColumn.AutoIncrementStep = 1

    and add this column to your dataset.table(0)



  • DataGridView and Autonumber