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. General Programming
  3. C#
  4. adding data in drop down from database

adding data in drop down from database

Scheduled Pinned Locked Moved C#
database
6 Posts 3 Posters 7 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.
  • U Offline
    U Offline
    ursbuddy
    wrote on last edited by
    #1

    i want yo know that how i can add data from a table into a drop down.

    ursbuddy

    I A 2 Replies Last reply
    0
    • U ursbuddy

      i want yo know that how i can add data from a table into a drop down.

      ursbuddy

      I Offline
      I Offline
      il_masacratore
      wrote on last edited by
      #2

      Hi, For example, you can fill a Dataset using ADO.NET (Oledbconnection, OledbAdapter and Oledbcommand) and then set in the dropdown the property DataSource the dataset as value. Example of the dataset filling: //create the conn OleDbConnection con = new OleDbConection("conection string"); //create the command OleDbCommand cmd = new OleDbCommand("SELECT FROM ", con); //create the DataAdapter & DataSet OleDbDataAdapter da = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); //fill the DataSet da.Fill(ds);

      U 1 Reply Last reply
      0
      • U ursbuddy

        i want yo know that how i can add data from a table into a drop down.

        ursbuddy

        A Offline
        A Offline
        albCode
        wrote on last edited by
        #3

        SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["YourConnStr"].ConnectionString;//YourConnStr is initialized in web.config file SqlDataSource1.SelectCommand = "select * from yourtablename"; //Set SQL Command SqlDataSource1.DataSourceID = "SqlDataSource1";//Set DataSource ID, in this case DatasourceID is SqlDataSource1 SqlDataSource1.DataTextField = "ColText";//DataTextField represent text, which is displayed in DropDownList SqlDataSource1.DataValueField = "ColVal";";//DataValueField represent value SqlDataSource1.DataBind(); Hope this helps


        "My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates

        U 1 Reply Last reply
        0
        • I il_masacratore

          Hi, For example, you can fill a Dataset using ADO.NET (Oledbconnection, OledbAdapter and Oledbcommand) and then set in the dropdown the property DataSource the dataset as value. Example of the dataset filling: //create the conn OleDbConnection con = new OleDbConection("conection string"); //create the command OleDbCommand cmd = new OleDbCommand("SELECT FROM ", con); //create the DataAdapter & DataSet OleDbDataAdapter da = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); //fill the DataSet da.Fill(ds);

          U Offline
          U Offline
          ursbuddy
          wrote on last edited by
          #4

          thnxs very much i'l try this. u people are very helpful thnxs again

          ursbuddy

          1 Reply Last reply
          0
          • A albCode

            SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["YourConnStr"].ConnectionString;//YourConnStr is initialized in web.config file SqlDataSource1.SelectCommand = "select * from yourtablename"; //Set SQL Command SqlDataSource1.DataSourceID = "SqlDataSource1";//Set DataSource ID, in this case DatasourceID is SqlDataSource1 SqlDataSource1.DataTextField = "ColText";//DataTextField represent text, which is displayed in DropDownList SqlDataSource1.DataValueField = "ColVal";";//DataValueField represent value SqlDataSource1.DataBind(); Hope this helps


            "My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates

            U Offline
            U Offline
            ursbuddy
            wrote on last edited by
            #5

            thnxs for this.

            ursbuddy

            A 1 Reply Last reply
            0
            • U ursbuddy

              thnxs for this.

              ursbuddy

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

              you are welcome... example which i posted before to you it's in VS2005


              "My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates

              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