?
Solved

add row and call its fieldname "ID" to dynamically created dataset

Posted on 2006-03-31
1
Medium Priority
?
176 Views
Last Modified: 2010-04-23
Hi, i want to create a Dataset dynamically,
no problem. i want to add a row called "ID" to my table "MyID"
the problem is adding the row.
i have Row(0) = and this does not work.
i also dont know how to call the row field "ID"

thanks!

        Dim ds As New DataSet
        Dim dt As New System.Data.DataTable("MyID")  
        ds.Tables.Add(dt)

        Dim I As Integer
        For I = 0 To ListView1.Items.Count - 1
            Dim row As DataRow = ds.Tables("MyID").NewRow()
            row(0) = ListView1.Items(I).SubItems(9).Text.Trim.ToUpper
            ds.Tables("MyID").Rows.Add(row)
        Next I

        ds.WriteXml("c:\1.xml")
0
Comment
Question by:jxharding
1 Comment
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 16340653
Hi jxharding,

You haven't actually added a column to your datatable:

        Dim ds As New DataSet
        Dim dt As New System.Data.DataTable("MyID")
        dt.Columns.Add("ID")
        ds.Tables.Add(dt)

        Dim I As Integer
        For I = 0 To  ListView1.Items.Count - 1
            Dim row As DataRow = ds.Tables("MyID").NewRow()
            row.Item("ID") =  ListView1.Items(I).SubItems(9).Text.Trim.ToUpper
            ds.Tables("MyID").Rows.Add(row)
        Next I

        ds.WriteXml("c:\1.xml")

This adds a column called ID to the datatable, then you can refer to this by name as row.Item("ID")

Tim Cottee
0

Featured Post

Independent Software Vendors: 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

840 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