View Full Version : Getting a single value from a database.

01-01-2006, 04:02 AM

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)
dg.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleResult)
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!


01-01-2006, 04:10 AM

You should look into ExecuteScalar (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataoledboledbcommandclassexecutescalartopic.asp)

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

Good luck :)

01-01-2006, 04:22 AM
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)

01-01-2006, 04:31 AM
You're welcome and keep it up :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum