Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

datatable add row

Posted on 2006-11-17
6
Medium Priority
?
256 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

886 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