By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,758 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,758 IT Pros & Developers. It's quick & easy.

Autoincrement Column contains null Values

rizwan6feb
100+
P: 108
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
Expand|Select|Wrap|Line Numbers
  1. Dim dc As New DataColumn("Serial",System.Type.GetType("System.Int32"))
  2.         dc.AutoIncrement = True
  3.         dc.AutoIncrementSeed = 1
  4.         dc.AutoIncrementStep = 1
  5.         dt.Columns.Add(dc)
  6.  
'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
Dec 25 '08 #1
Share this Question
Share on Google+
1 Reply


MrMancunian
Expert 100+
P: 569
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
Dec 29 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.