...

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



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

Brandoe85
01-01-2006, 04:10 AM
Hi,

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 :)

snow
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)

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum