datatable add row

I want to add a row in the middle of my datatable, any hint ?
TheSonicsAsked:
Who is Participating?
 
ZeonFlashConnect With a Mentor Commented:
Did you want to insert the row directly in the middle, or just be able to put it anywhere?

Dim dr As DataRow = dt.NewRow
dr("col1") = 1
dr("col2") = 2

'This will insert the row at index 5
dt.Rows.InsertAt(dr, 5)

'This will insert the row in the middle of the table
dt.Rows.InsertAt(dr, dt.Rows.Count / 2)

riyazthad, your solution will insert a row, but it will be at the end of the table.
0
 
riyazthadCommented:
   Dim table As DataTable = dataSet.Tables("TableName")
    Dim dr As DataRow = table.NewRow()

    dr("Field1") = "value1"
    dr("Field2") = "value2"
    table.Rows.Add(dr)

Thad
0
 
riyazthadCommented:
yes you are right. I didnt look into his actual requirement. I thought he is asking just to add row.

0
All Courses

From novice to tech pro — start learning today.