Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2005
    Location
    The Lone Star State
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retrieving Value from a DataColumn

    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:


    Code:
    lblJobName.Text = ds.Tables("MASTER_JCM_R1").Rows[0].(Item("JDESC").Value)
    I've also tried:

    Code:
    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!

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Have you tried this?
    Code:
    lblJobName.Text = ds.Tables("MASTER_JCM_R1").Rows(0).Item("JDESC")
    Good luck;

  • #3
    New Coder
    Join Date
    May 2005
    Location
    The Lone Star State
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Brando!

    Thank you sir!

    The final line that worked properly came to be this:

    Code:
    lblJobName.Text = ds.Tables("MASTER_JCM_R1").Rows(0).Item("JDESC").ToString()
    I really appreciate the brain jump-start. Much obliged!

  • #4
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    i don't know why but mentioning the names of table and column gave me a null refence error... so i used index instead... which worked...
    Code:
    lblJobName.Text = ds.Tables(0).Rows(0).Item(3)
    - NS 666
    .net DEVILoper

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Glad you got it working


    Quote Originally Posted by Nischumacher
    i don't know why but mentioning the names of table and column gave me a null refence error... so i used index instead... which worked...
    Code:
    lblJobName.Text = ds.Tables(0).Rows(0).Item(3)
    The Tables and Item properties are overloaded, you can either access them by name, or index. In order to access the Table property by name, you would have to specify a name when you add the table. For the item, as long as the column you want is in your table, you should be able to reference by it's name as well.


  •  

    Posting Permissions

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