• Retrieving Value from DataColumn (VB.net)

    Home » Forums » Developers, developers, developers » DevOps Lounge » Retrieving Value from DataColumn (VB.net)

    Author
    Topic
    #426631

    Hello All!!

    Can’t figure out for the life of me how to get the value from a DataColumn and throw it in a label. I’ve tried about every variation I can think of, and no dice. I know the DataSet/DataTable was populated correctly, and I know the name of the column I want is “JDESC”

    Here’s the code:

    lblJobName.Text = ds.Tables(“MASTER_JCM_R1”).Rows[0].(Item(“JDESC”).Value)

    I’ve also tried:

    ds.Tables(“MASTER_JCM_R1”).Columns(“JDESC”).Value
    ds.Tables(“MASTER_JCM_R1”).Columns(“JDESC”).ToString()
    ds.Tables(“MASTER_JCM_R1”).Rows[0].Item(“JDESC”).ToString()

    …a few others as well. ALL generate the error:

    Value of type ‘System.Data.DataRowCollection’ cannot be converted to ‘String’

    Help! Thanks so much!

    Viewing 0 reply threads
    Author
    Replies
    • #986480

      Try this:

      lblJobName.Text = ds.Tables(“MASTER_JCM_R1”).Rows(0).Item(“JDESC”).Value.ToString()

      • #986604

        Charlotte,

        Thank you! You’re advice gave me the little jump I needed to get her jammin’! In the end, I removed the Value and so the final line looks like this:

        lblJobName.Text = ds.Tables(“MASTER_JCM_R1”).Rows(0).Item(“JDESC”).ToString()

        You’re the best! Thanks so much!

        • #986612

          I still have trouble remembering when you need Value and when you don’t, so I’m glad you figured it out. The rest is very standard syntax for .Net. thumbup

    Viewing 0 reply threads
    Reply To: Retrieving Value from DataColumn (VB.net)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: