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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to bring a database record to DropdownList in asp .net app?

How to bring a database record to DropdownList in asp .net app?

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasetutorialquestion
7 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.
  • P Offline
    P Offline
    Praveen 123
    wrote on last edited by
    #1

    Hi, I am doing a asp.net app.My backend is MS-Access.Plaes send me the code to bring a access data base record to the DropdownList. Eg:To list all employee_names in a table to DropownList.

    Praveen.K System Engineer Graviton Technologies Pvt.Ltd

    K 1 Reply Last reply
    0
    • P Praveen 123

      Hi, I am doing a asp.net app.My backend is MS-Access.Plaes send me the code to bring a access data base record to the DropdownList. Eg:To list all employee_names in a table to DropownList.

      Praveen.K System Engineer Graviton Technologies Pvt.Ltd

      K Offline
      K Offline
      krishnakumark
      wrote on last edited by
      #2

      Hi Praveen if you are using .net 2.0, You either use datareader and attach that with the dropdownlist (.net 1.1 and .net 2.0) OR create a acces datasource and attach it with the dropdown list... Krishna Kumar

      Kk

      P 1 Reply Last reply
      0
      • K krishnakumark

        Hi Praveen if you are using .net 2.0, You either use datareader and attach that with the dropdownlist (.net 1.1 and .net 2.0) OR create a acces datasource and attach it with the dropdown list... Krishna Kumar

        Kk

        P Offline
        P Offline
        Praveen 123
        wrote on last edited by
        #3

        Sir that attaching code i am asking,My data base is attached to the page using oledb connection.Now on loading the page i want to display the data base records on the DropdownList

        Praveen.K System Engineer Graviton Technologies Pvt.Ltd

        K 1 Reply Last reply
        0
        • P Praveen 123

          Sir that attaching code i am asking,My data base is attached to the page using oledb connection.Now on loading the page i want to display the data base records on the DropdownList

          Praveen.K System Engineer Graviton Technologies Pvt.Ltd

          K Offline
          K Offline
          krishnakumark
          wrote on last edited by
          #4

          Hi ..Try this..dont forget to include System.Data.OleDb namespace OleDbConnection con= new OleDbConnection("Place your connection string here"); string sql="select id,name from users"; OleDbCommand sqlcmd = new OleDbCommand(sql,con); con.Open(); DropDownList1.DataSource= sqlcmd.ExecuteReader(CommandBehavior.CloseConnection); DropDownList1.DataTextField = "name"; DropDownList1.DataValueField = "id"; DropDownList1.DataBind();

          Kk

          P 1 Reply Last reply
          0
          • K krishnakumark

            Hi ..Try this..dont forget to include System.Data.OleDb namespace OleDbConnection con= new OleDbConnection("Place your connection string here"); string sql="select id,name from users"; OleDbCommand sqlcmd = new OleDbCommand(sql,con); con.Open(); DropDownList1.DataSource= sqlcmd.ExecuteReader(CommandBehavior.CloseConnection); DropDownList1.DataTextField = "name"; DropDownList1.DataValueField = "id"; DropDownList1.DataBind();

            Kk

            P Offline
            P Offline
            Praveen 123
            wrote on last edited by
            #5

            sir, What the "name" and "id" reprecents....Because both are bringing to the same dropdown list..

            Praveen.K System Engineer Graviton Technologies Pvt.Ltd

            K 1 Reply Last reply
            0
            • P Praveen 123

              sir, What the "name" and "id" reprecents....Because both are bringing to the same dropdown list..

              Praveen.K System Engineer Graviton Technologies Pvt.Ltd

              K Offline
              K Offline
              krishnakumark
              wrote on last edited by
              #6

              Name is the test .. which will be displayed in the dropdown .. and id is the value which will be stroed internally...

              Kk

              K 1 Reply Last reply
              0
              • K krishnakumark

                Name is the test .. which will be displayed in the dropdown .. and id is the value which will be stroed internally...

                Kk

                K Offline
                K Offline
                krishnakumark
                wrote on last edited by
                #7

                sorry for the mistake... Name is the text (and not test) .. which will be displayed in the dropdown .. and id is the value which will be stroed internally...

                Kk

                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