[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Create dataset programatically in vb.net 2005

Posted on 2007-08-01
2
Medium Priority
?
1,283 Views
Last Modified: 2013-11-26
Hi,

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
Lee
0
Comment
Question by:ljhodgett
  • 2
2 Comments
 
LVL 6

Expert Comment

by:ToFro
ID: 19608957
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
        dt.Rows.Add(row)
        ds.Tables.Add(dt)
0
 
LVL 6

Accepted Solution

by:
ToFro earned 2000 total points
ID: 19609046
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))
        ds.Tables.Add(dt)


... 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
        ds.Tables("table1").Rows.Add(row)
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

834 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