vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Sunday, March 13, 2011

How to insert a new row in a Datatable in vb.Net..


hi...

Here i am describe how to insert a new row in a datatable using vb code
In my application  i need an requirement to insert a new row into datatable after getting the data from the database.
i googled but i didnt get the proper result for my need ,after deep search i found the result ,
By using this code you can insert new row at any position in the datatable...

For an examble if you want to insert a new row in 0th postion ..let see the code

Dim dr as  datarow


dr = dt.NewRow()
        For j = 0 To dt.Columns.Count - 1


            Select Case j
                Case 0
                    dr("column1") = "Name"
                Case 1
                    dr("column2") = " Number"
                Case 2
                    dr("column3") = "Address"
            End Select
        Next


        dt.Rows.InsertAt(dr, 0)  'Here 0 denotes postion of the row to insert....

i hope this one helpfull to u.....

0 comments:

Post a Comment