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 01-01-2006, 04:02 AM   PM User | #1
snow
New Coder

 
Join Date: Jun 2005
Location: Scotland
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
snow is an unknown quantity at this point
Question Getting a single value from a database.

Hello!

I need a bit of help please! Basically, I'm trying to get a single value from my database and eventually shove it into a label. I'm very new to ASP.NET (I got it 3 days ago), so in my head I thought this should be really easy...

This is the relevent bit:

Dim cmd As OdbcCommand = New OdbcCommand("SELECT price FROM pricing WHERE canvas='" + DropDownList2.SelectedValue() + "' AND size='" + DropDownList1.SelectedValue() + "' AND framed='" + framed.SelectedValue() + "'", con)
con.Open()
dg.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleResult)
dg.DataBind()
dgi = dg.SelectedItem
value = dgi.ToString()
Label1.Text = value

* dg stands for DataGrid, dgi a DataGridItem

what it says now is that dgi is null... could someone please give me some pointers? Thanks very much!

Sarah
(Snow)
snow is offline   Reply With Quote
Old 01-01-2006, 04:10 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
Hi,

You should look into ExecuteScalar

Give that a try. If you run into any problems let us know.

Good luck
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 01-01-2006, 04:22 AM   PM User | #3
snow
New Coder

 
Join Date: Jun 2005
Location: Scotland
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
snow is an unknown quantity at this point
That worked perfectly!

Thanks so much!
And thank you for replying so quickly, sorry for my problem being so small, I just couldn't find the right thing anywhere, that was really great! Thank you!

Sarah (Snow)
snow is offline   Reply With Quote
Old 01-01-2006, 04:31 AM   PM User | #4
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
You're welcome and keep it up
__________________
-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 10:12 PM.


Advertisement
Log in to turn off these ads.