Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-22-2005, 09:00 PM   PM User | #1
reverendleo
New Coder

 
Join Date: May 2005
Location: The Lone Star State
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
reverendleo is an unknown quantity at this point
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!
reverendleo is offline   Reply With Quote
Old 11-23-2005, 04:15 AM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Have you tried this?
Code:
lblJobName.Text = ds.Tables("MASTER_JCM_R1").Rows(0).Item("JDESC")
Good luck;
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 11-23-2005, 01:42 PM   PM User | #3
reverendleo
New Coder

 
Join Date: May 2005
Location: The Lone Star State
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
reverendleo is an unknown quantity at this point
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!
reverendleo is offline   Reply With Quote
Old 11-23-2005, 01:49 PM   PM User | #4
Nischumacher
Regular Coder

 
Nischumacher's Avatar
 
Join Date: Oct 2005
Location: Bombay, India
Posts: 196
Thanks: 0
Thanked 2 Times in 2 Posts
Nischumacher has a little shameless behaviour in the past
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
Nischumacher is offline   Reply With Quote
Old 11-23-2005, 02:18 PM   PM User | #5
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
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.
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:32 PM.


Advertisement
Log in to turn off these ads.