Autoincrement Column contains null Values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rizwan6feb
    New Member
    • Jul 2007
    • 108

    Autoincrement Column contains null Values

    I have a DataTable with thousands of records, i want to show these records on per page basis ( i.e a DataGridView showing first 20 records and next button to show next 20 records ...)

    To achieve this, i have added an Autoincrement Column to the DataTable so that i can use a filter on the Autoincrement Column to get the desired 20 records from the DataTable. I have used the following code
    Code:
    Dim dc As New DataColumn("Serial",System.Type.GetType("System.Int32"))
            dc.AutoIncrement = True
            dc.AutoIncrementSeed = 1
            dc.AutoIncrementStep = 1
            dt.Columns.Add(dc)
    'dt' is the object of DataTable


    When i set the datasource of DataGridView to this DataTable, i see null values in the Serial Column

    Question is:
    How can i get the Autoincrement Column working (with values)

    I can't query the database, all i have to do is play around with the available DataTable
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    AutoIncrement will only work for newly added rows to a datatable. Not for an extra column you add to a datatable. Why don't you use the rownumber of the datatable as Serial? After all, that is a unique AutoIncement number.

    Steven

    Comment

    Working...