Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Pass value from dropdownlist to SQL select using SelectedIndexChanged?

Pass value from dropdownlist to SQL select using SelectedIndexChanged?

Scheduled Pinned Locked Moved ASP.NET
databasedebugginghelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FionaDM
    wrote on last edited by
    #1

    I want to pass a(numerical) value from a dropdownlist to an SQL select using the DropDownList SelectedIndexChanged event. Here's my code so far. protected void MyDropDownList_SelectedIndexChanged(object sender, EventArgs e) { DropDownList MyDropDownList = (DropDownList)("MyDropDownList"); MyLabel.Text = MyDefinitionDropDownList.SelectedItem.Value.ToString(); string strSQL; strSQL = "SELECT COUNT(*) as count from MyTable where ID= ???"; } My problem is that I don't know what should replace the '???'. I've tried strSQL = "SELECT COUNT(*) as count from MyTable where ID= MyLabel.Text"; but this is interpreted as "SELECT COUNT(*) as count from MyTable where ID= MyLabel.Text" even though my debugger tells me MyLabel.Text is grabbing an OK value. If I do strSQL = "SELECT COUNT(*) as count from MyTable where ID= 6" for example it works fine. I think my problem is with casting? Thanks Majella

    _ 1 Reply Last reply
    0
    • F FionaDM

      I want to pass a(numerical) value from a dropdownlist to an SQL select using the DropDownList SelectedIndexChanged event. Here's my code so far. protected void MyDropDownList_SelectedIndexChanged(object sender, EventArgs e) { DropDownList MyDropDownList = (DropDownList)("MyDropDownList"); MyLabel.Text = MyDefinitionDropDownList.SelectedItem.Value.ToString(); string strSQL; strSQL = "SELECT COUNT(*) as count from MyTable where ID= ???"; } My problem is that I don't know what should replace the '???'. I've tried strSQL = "SELECT COUNT(*) as count from MyTable where ID= MyLabel.Text"; but this is interpreted as "SELECT COUNT(*) as count from MyTable where ID= MyLabel.Text" even though my debugger tells me MyLabel.Text is grabbing an OK value. If I do strSQL = "SELECT COUNT(*) as count from MyTable where ID= 6" for example it works fine. I think my problem is with casting? Thanks Majella

      _ Offline
      _ Offline
      _AK_
      wrote on last edited by
      #2

      Hi, You do like this: strSQL = "SELECT COUNT(*) as count from MyTable where ID=" + MyLabel.Text; Hope this will solve the problem. :) Best Regards, Apurva Kaushal

      F 1 Reply Last reply
      0
      • _ _AK_

        Hi, You do like this: strSQL = "SELECT COUNT(*) as count from MyTable where ID=" + MyLabel.Text; Hope this will solve the problem. :) Best Regards, Apurva Kaushal

        F Offline
        F Offline
        FionaDM
        wrote on last edited by
        #3

        Thanks Majella

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups