Solved

datatable add row

Posted on 2006-11-17
6
250 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now