Solved

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

Posted on 2006-07-13
3
597 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

627 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