Results 1 to 6 of 6

Thread: [RESOLVED] DataTable

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    92

    Resolved [RESOLVED] DataTable

    Hi, I want to know how can I read a datatable. I am using this code:
    objDataAdapter.Fill(objDataSet, "Outlookbar")
    lblArchives.Text = CStr(objDataSet.Tables("Outlookbar").Rows(1).ToString)

    the second line doesn't return the value I want. Instead it returns System.Data.DataRow.
    What should I change?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DataTable

    Moved from the CodeBank

  3. #3

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: DataTable

    You're close. You need:

    datasetname.Tables(tablename).Rows(rownumber).Item(columnname).ToString()

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: DataTable

    A DataTable contains DataRows. Each DataRow contains Items. Think of it as an excel sheet. To read the value of an individual cell, you have to go to that particular cell. To read values from all cells in a row, you can do a loop, something like this
    Code:
    'Get the 1st row in the datatable
    Dim row As DataRow = objDataSet.Tables("Outlookbar").Rows(0)
    'Loop thru all the items in that row and get their values
    For Each itm As Object in row.Items
        Debug.WriteLine(itm.ToString)
    Next
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    92

    Re: DataTable

    I really, appreciated that you helped me. It works.
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width