Solved

datatable add row

Posted on 2006-11-17
6
252 Views
Last Modified: 2010-04-23
I want to add a row in the middle of my datatable, any hint ?
0
Comment
Question by:TheSonics
  • 2
6 Comments
 
LVL 6

Expert Comment

by:riyazthad
ID: 17969743
   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
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 17969774
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
 
LVL 6

Expert Comment

by:riyazthad
ID: 17970309
yes you are right. I didnt look into his actual requirement. I thought he is asking just to add row.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
start a process from a service 3 36
vb.net class 3 28
System.net.Sockets Error 5 38
MYSQL responding very slow 3 48
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question