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. Database & SysAdmin
  3. Database
  4. Pass value from dropdownlist to SQL select using SelectedIndexChanged?

Pass value from dropdownlist to SQL select using SelectedIndexChanged?

Scheduled Pinned Locked Moved Database
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

    R 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

      R Offline
      R Offline
      Rob Graham
      wrote on last edited by
      #2

      try: strSQL = "SELECT COUNT(*) as count from MyTable where ID=' " + MyLabel.Text + " ' "; Or better yet use parameters (see Colin Mackay's article here[^]) for reasons and examples. We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest. Patricia Aburdene

      F 1 Reply Last reply
      0
      • R Rob Graham

        try: strSQL = "SELECT COUNT(*) as count from MyTable where ID=' " + MyLabel.Text + " ' "; Or better yet use parameters (see Colin Mackay's article here[^]) for reasons and examples. We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest. Patricia Aburdene

        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