DataTable Reading.....

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