Friday, May 30, 2008

Table Clone in ASP.Net

'Assuming we have table in our dataset called 'ds'

Dim tempTable As DataTable
tempTable = ds.Tables(0).Clone

'Creating columns with datatypes
For k As Integer = 1 To 11
tempTable.Columns("col" & k).DataType = System.Type.GetType("System.Int32")
Next

'Importing Rows
For Each dr1 As DataRow In ds.Tables(1).Rows
tempTable.ImportRow(dr1)
Next

'Adding table to existing dataset.
tempTable.TableName = "NewTempTable"
ds.Tables.Add(tempTable)

Thats it.

Regards

No comments: