DataTable Reading.....

P

Pete Smith

What is the syntax to read the data from a DataTable by row # and (column #
or name)?

..Net Framework 1.1 and VB.Net.

I have the below code from documentation



For Each thisTable In myDataSet.Tables
' For each row, print the values of each column.
Dim myRow As DataRow
For Each myRow In thisTable.Rows
Dim myCol As DataColumn
For Each myCol In thisTable.Columns
Console.WriteLine(myRow(myCol))
Next myCol
Next myRow
Next thisTable

But I wanted read the datatable data by referencing as above specified.



Thank you,

-Pete
 
C

Chris

Pete said:
What is the syntax to read the data from a DataTable by row # and (column #
or name)?

.Net Framework 1.1 and VB.Net.

I have the below code from documentation



For Each thisTable In myDataSet.Tables
' For each row, print the values of each column.
Dim myRow As DataRow
For Each myRow In thisTable.Rows
Dim myCol As DataColumn
For Each myCol In thisTable.Columns
Console.WriteLine(myRow(myCol))
Next myCol
Next myRow
Next thisTable

But I wanted read the datatable data by referencing as above specified.



Thank you,

-Pete

For Each thisTable In myDataSet.Tables
' For each row, print the values of each column.
Dim myRow As DataRow
For Each myRow In thisTable.Rows
Dim myCol As DataColumn
For ii as integer = 0 to thisTable.Columns -1
Console.WriteLine(myRow(ii))
Next myCol
Next myRow
Next thisTable
 
C

Chris

Chris said:
For Each thisTable In myDataSet.Tables
' For each row, print the values of each column.
Dim myRow As DataRow
For Each myRow In thisTable.Rows
Dim myCol As DataColumn
For ii as integer = 0 to thisTable.Columns -1
Console.WriteLine(myRow(ii))
Next myCol
Next myRow
Next thisTable


Oh, and your way doesn't work because a MyRow object does not contain a
DataColumn. Only the datatable contains a column object.

Chris
 
C

Chris

Pete said:
Is there anyway I can read cell(x,y) in the DataTable?
Thank you,
-Pete

My example just showed you how to read every cell in the datatable.

To be more exact:
myDataSet.Tables(Z).Rows(Y).Item(X)

Chris
 
P

Pete Smith

Thank you,
-Pete

Chris said:
My example just showed you how to read every cell in the datatable.

To be more exact:
myDataSet.Tables(Z).Rows(Y).Item(X)

Chris
 

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