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

Posted on 2006-03-31
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"


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

        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
        Next I

Question by:jxharding
    1 Comment
    LVL 44

    Accepted Solution

    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")

            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
            Next I


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

    Tim Cottee

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 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

    13 Experts available now in Live!

    Get 1:1 Help Now