Solved

datatable add row

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Close form "before" open 3 49
How to open form using item in Listbox. 8 23
Calculate number of nights between two dates 5 53
Complex SQL statement in VB.NET 7 31
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

861 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