Solved

create a dataset or maybe datatable on the fly vb.net

Posted on 2006-07-13
3
581 Views
Last Modified: 2006-11-18
I am trying to add content to a datagrid.

I was under the impression that the only way to do this is by adding data from a datatabel or dataset.

How do you create either from scratch, give column names, then fill with data.

I want it to look like this

"ID", "name", "phone number"
1, "jack", "555-5555"
2, "joe", "555-4444"

I think after I have that, I can add it to a datagrid.

Thanks
0
Comment
Question by:jackjohnson44
3 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 17103364
       Dim ds As New DataSet
        Dim dr As DataRow

        'Add a new table to the dataset
        ds.Tables.Add()

        'Create the columns in the data table
        ds.Tables(0).Columns.Add("ID")
        ds.Tables(0).Columns.Add("name")
        ds.Tables(0).Columns.Add("phone number")

        'Create a new row for the data table
        dr = ds.Tables(0).NewRow

        'Set the values for the row
        dr.Item("ID") = 1
        dr.Item("name") = "John Doe"
        dr.Item("phone number") = "555-5555"

        'Add the row to the table
        ds.Tables(0).Rows.Add(dr)

        'Repeat as necessary

        'Bind the dataset to the datagrid
        DataGrid1.DataSource = ds.Tables(0)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17103799
where will you be getting the values from?
0
 

Author Comment

by:jackjohnson44
ID: 17107930
I am going to create it on the fly as an internal place to store info for my app.
I was using recordsets in vb6.

If you want to format some members when you set the data source how do you do that,
since nothing looped, you can't look at every member?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

11 Experts available now in Live!

Get 1:1 Help Now