We help IT Professionals succeed at work.
Get Started

Retrieving values from Dataset

juststeve
juststeve asked
on
352 Views
Last Modified: 2012-05-05
I'm at a point in code where I need to pull a descrete value from a dataset. I understand I have to drive throught the DataTable first, but I thought the next stop would be the column value:

ds.Tables(0)("unit")

The help files lead me to some code that iterates thru datatables that will return values for me but doesn't help me understand how to explictly reference an individual column's value. Also, it would be helpful to debug.write out the column names so i can verify the structure of a given table - it sure seems like that would be a simple matter of changing 'myRow(myCol)' to 'myRow(myCol.ColumnName)' - that produces the exact same output.

    Private Sub PrintRows(ByVal myDataSet As DataSet)
        Dim thisTable As DataTable
        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
                    Debug.Write(vbCrLf)
                    Debug.Write(myRow(myCol)
                Next myCol
            Next myRow
        Next thisTable
    End Sub
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE