Create dataset programatically in 2005

Posted on 2007-08-01
Last Modified: 2013-11-26

I'm trying to find out how to create a dataset and table programatically.

Basically I need a table that will store textbox1.text in column 1 and textbox2.text in column 2

How do I do this please?

Many thanks
Question by:ljhodgett
    LVL 6

    Expert Comment

    Try this:

            Dim ds As New DataSet
            Dim dt As New DataTable("table1")

            dt.Columns.Add("Column1", GetType(String))
            dt.Columns.Add("Column2", GetType(String))

            Dim row As DataRow = dt.NewRow
            row("Column1") = TextBox1.Text
            row("Column2") = TextBox2.Text
    LVL 6

    Accepted Solution

    Hi there again, I'm assuming you are familar with events. You could use the code like this:

    ... declare the DataSet globally

        Private ds As DataSet

    ... then create the DataTable and columns on page load:

            ds = New DataSet
            Dim dt As DataTable = New DataTable("table1")
            dt.Columns.Add("Column1", GetType(String))
            dt.Columns.Add("Column2", GetType(String))

    ... every time you want to add a row, do this(e.g. behind a button event):

            Dim row As DataRow = ds.Tables("table1").NewRow
            row("Column1") = TextBox1.Text
            row("Column2") = TextBox2.Text

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    732 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

    24 Experts available now in Live!

    Get 1:1 Help Now