Multiple Table DataSet

S

samoore33

I want to list all of the items in a dataset in a textbox. The dataset
has multiple tables. When I try to use the code below, even though I
dim myState as the DataTable("state"). It still looks for othe rows in
the dataset.

Dim myState As DataTable = myDataSet.Tables("state")
Dim myTax As DataTable = myDataSet.Tables("Tax")
Dim row As DataRow
Dim column As DataColumn


For Each myState In myDataSet.Tables
For Each row In myState.Rows
For Each column In myState.Columns
txtList.Text += row("id").ToString()
Next
Next
Next

A friend sent me some code that parses the DataSet and shows me the
structure of it. The first table is called "state" and the third table
is called "Tax".

Any help would be appreciated.

Scott Moore
 
I

Izzy

The reason for this is this line:

For Each myState In myDataSet.Tables

Even though your setting it to a specific table, this line sets it to
each table in the dataset starting with table(0).

When you say you want to list all the ITEMS do you mean data in the
columns or do you want to list the column names?

This is how you list the data in each column in a table.

Dim table As DataTable = dataset.tables("Whatever")
Dim row As DataRow
Dim b As Byte

For Each row In table.Rows
For b = 0 To table.Columns.Count - 1
TextBox1.Text = TextBox1.Text & row(b)
Next
Next


This is how you list each column name in the table.

Dim table As DataTable
Dim row As DataRow
Dim column As DataColumn

For Each row In table.Rows
For Each column In table.Columns
TextBox1.Text = TextBox1.Text & column.ColumnName
Next
Next
 
C

Cor Ligthert [MVP]

Izzy,

You know that it is more expensive to take a byte as indexer.
The cheapest one one a 32bit system is the integer (int32).

(Your process to set it in the accumulator register takes more than that 3
bytes that you think to save).

Cor
 
C

Cor Ligthert [MVP]

Scott,

Why not just use a datagrid

mydatagrid.datasource = myDataset

Otherwise you have to loop through this set which all contains collections
dataset (has a collection of datatables with the name tables)
datatables (has a collecion of datarows with the name rows
datarows (has a collection of items which are the default)

All the collections have a count, while they all can be indexed by an
integer.

I hope this helps,

Cor
 
S

samoore33

Cor,

Believe me I would love to use a datagrid, I have a lot more experience
with datagrids. They want the information to populate a text box rather
then a datagrid.

Fun fun fun

Scott
 
C

Cor Ligthert [MVP]

Scott,

And you know now how to do it?

Cor

samoore33 said:
Cor,

Believe me I would love to use a datagrid, I have a lot more experience
with datagrids. They want the information to populate a text box rather
then a datagrid.

Fun fun fun

Scott
 
S

samoore33

Cor,

Yes. I used what Izzy gave me to figure it out. I really do appreciate
the help from both Izzy and you.

Thanks a lot!

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top