Multiple Table DataSet

  • Thread starter Thread starter samoore33
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
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
 
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
 
Back
Top