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 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2005
    Location
    Scotland
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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)

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Hi,

    You should look into ExecuteScalar

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

    Good luck

  • #3
    New Coder
    Join Date
    Jun 2005
    Location
    Scotland
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You're welcome and keep it up


  •  

    Posting Permissions

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