Sunday, March 30, 2008

remove duplicate row in datatable

Dim dt as new DataTable 'Assume this is the existing data table, populated somehow...
Dim dtNew as new DataTable
Dim dr as DataRow
Dim ID as Int32 = -1

dtNew=dt.Clone 'For having the same structure

for each dr in dt.Rows

If ID=-1 or ID <> Int32.Parse(dr("ID").ToString) Then
dtNew.ImportRow (dr)
ID = Int32.Parse(dr("ID").ToString)
End If

next

Hope this helps!!

No comments: