469,646 Members | 1,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

Autoincrement Column contains null Values

rizwan6feb
108 100+
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
1 3518
MrMancunian
569 Expert 512MB
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.

Similar topics

2 posts views Thread by RA | last post: by
reply views Thread by Agnes | last post: by
6 posts views Thread by Dennis | last post: by
5 posts views Thread by JC Voon | last post: by
1 post views Thread by Grzes_P | last post: by
6 posts views Thread by =?iso-8859-2?Q?Marcin_Dzi=F3bek?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.