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. how to get values from the database to a dropdown list [modified]

how to get values from the database to a dropdown list [modified]

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-netsql-serversysadmin
6 Posts 5 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.
  • D Offline
    D Offline
    dbn831
    wrote on last edited by
    #1

    please send me the code to get values from the database(SQL Server 2000) to a dropdown list in ASP.Net. -- modified at 3:14 Friday 24th August, 2007

    B C V A 5 Replies Last reply
    0
    • D dbn831

      please send me the code to get values from the database(SQL Server 2000) to a dropdown list in ASP.Net. -- modified at 3:14 Friday 24th August, 2007

      B Offline
      B Offline
      bigbrownbeaver
      wrote on last edited by
      #2

      Which database? Which language? Use an OleDbConnection and a command object to perform a sql query and then as you loop through your results populate the list. You can find documentation on this in the MSDN.

      1 Reply Last reply
      0
      • D dbn831

        please send me the code to get values from the database(SQL Server 2000) to a dropdown list in ASP.Net. -- modified at 3:14 Friday 24th August, 2007

        C Offline
        C Offline
        chathu03j
        wrote on last edited by
        #3

        try the following code: C#: ----- SqlConnection con = new SqlConnection(connectionString); String sql = "SELECT FROM "; SqlCommand cmd =new SqlCommand(sql,con); SqlDataAdapter sda =new SqlDataAdapter(cmd); DataTable dt =new DataTable(); con.Open(); sda.Fill(dt); DropDownList1.DataSource =dt; DropDownList1.DataBind();

        1 Reply Last reply
        0
        • D dbn831

          please send me the code to get values from the database(SQL Server 2000) to a dropdown list in ASP.Net. -- modified at 3:14 Friday 24th August, 2007

          V Offline
          V Offline
          VanithaVasu
          wrote on last edited by
          #4

          SqlConnection con= new SqlConnection("Server=IBM;DataSource=Master;User Id=sa;Pwd=sa"); SqlDataAdapter ada=new SqlDataAdapter("select * from customer",con); DataSet ds=new DataSet(); ada.Fill(ds); DropDownList1.DataSource=ds1.Tables[0]; DropDownList1.DataTextField=ds1.Tables[0].Columns[1].ToString(); DropDownList1.DataValueField=ds1.Tables[0].Columns[1].ToString(); DropDownList1.DataBind();

          VanithaVasu

          1 Reply Last reply
          0
          • D dbn831

            please send me the code to get values from the database(SQL Server 2000) to a dropdown list in ASP.Net. -- modified at 3:14 Friday 24th August, 2007

            A Offline
            A Offline
            ash83
            wrote on last edited by
            #5

            First create Connection with database and then Dim databaseRecord As SqlDataAdapter Dim dstRecord As DataSet databaseRecord = New SqlDataAdapter("Select * from ", con) dstRecords = New DataSet databaseRecord .Fill(dstRecords) dropdownlistname.DataSource = dstRecords dropdownlistname.DataTextField = "" dropdownlistname.DataValueField = "" dropdownlistname.DataBind()

            ash83

            1 Reply Last reply
            0
            • D dbn831

              please send me the code to get values from the database(SQL Server 2000) to a dropdown list in ASP.Net. -- modified at 3:14 Friday 24th August, 2007

              A Offline
              A Offline
              ash83
              wrote on last edited by
              #6

              First create Connection with database and then Dim databaseRecord As SqlDataAdapter Dim dstRecord As DataSet databaseRecord = New SqlDataAdapter("Select * from ", con) dstRecords = New DataSet databaseRecord .Fill(dstRecords) dropdownlistname.DataSource = dstRecords dropdownlistname.DataTextField = "" dropdownlistname.DataValueField = "" dropdownlistname.DataBind() I hope this will workout

              ash83

              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