Creating an identity column in a datatable

O

Omavlana Omav

Hi,

I have created a datatable, dataadapter, added the table to a dataset
and filling the table.

Here I want to add an identity column to the above datatable and Later I
will use this identity colum for printing the records using print
document.

How to create an identity column that increments its value when each row
added to it.

Here is the code snippet... Pls help.

myCommand = New SqlClient.SqlCommand(mySql, gSQLConnection)
UsrAdapter = New SqlClient.SqlDataAdapter(myCommand)
myDataSet = New DataSet

Dim myDataTable As New DataTable("ShareHoldersAuditReport")
myDataSet.Tables.Add("ShareHoldersAuditReport")
Dim aColumn As DataColumn
aColumn = myconstraint
aColumn = New DataColumn("aaaa")
myDataSet.Tables("ShareHoldersAuditReport").Columns.Add(aColumn)
aColumn = New DataColumn("bbbb")
myDataSet.Tables("ShareHoldersAuditReport").Columns.Add(aColumn)
aColumn = New DataColumn("cccc")
myDataSet.Tables("ShareHoldersAuditReport").Columns.Add(aColumn)
UsrAdapter.Fill(myDataSet, "ShareHoldersAuditReport")
myTable = myDataSet.Tables("ShareHoldersAuditReport")
gSQLConnection.Close()



Regards.
 
P

Peter Foot [MVP]

You can set a column as unique and autoincrementing e.g.
aColumn.Unique = True
aColumn.AutoIncrement = True
Note also the AutoIncrementStep and AutoIncrementSeed properties.

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org




Hi,

I have created a datatable, dataadapter, added the table to a dataset
and filling the table.

Here I want to add an identity column to the above datatable and Later I
will use this identity colum for printing the records using print
document.

How to create an identity column that increments its value when each row
added to it.

Here is the code snippet... Pls help.

myCommand = New SqlClient.SqlCommand(mySql, gSQLConnection)
UsrAdapter = New SqlClient.SqlDataAdapter(myCommand)
myDataSet = New DataSet

Dim myDataTable As New DataTable("ShareHoldersAuditReport")
myDataSet.Tables.Add("ShareHoldersAuditReport")
Dim aColumn As DataColumn
aColumn = myconstraint
aColumn = New DataColumn("aaaa")
myDataSet.Tables("ShareHoldersAuditReport").Columns.Add(aColumn)
aColumn = New DataColumn("bbbb")
myDataSet.Tables("ShareHoldersAuditReport").Columns.Add(aColumn)
aColumn = New DataColumn("cccc")
myDataSet.Tables("ShareHoldersAuditReport").Columns.Add(aColumn)
UsrAdapter.Fill(myDataSet, "ShareHoldersAuditReport")
myTable = myDataSet.Tables("ShareHoldersAuditReport")
gSQLConnection.Close()



Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top