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. Load pID and productname to combobox - c sharp.

Load pID and productname to combobox - c sharp.

Scheduled Pinned Locked Moved C#
csharpdatabaseasp-netsql-serversysadmin
5 Posts 3 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.
  • M Offline
    M Offline
    misCafe
    wrote on last edited by
    #1

    Brothers, I've successfully coded to load data from db (sql server) to combobox in c sharp (ex: productname); but when I add new data to db (from c sharp), I want to add an pID of productname instead of the productname to db because I have two tables in db which have relationship together (ex: pID, productname) and (ex: cID, pID, qty, price). Lastly, I have another form to add more productname to db; so, how to refresh the combobox (as mentioned above) when this form is closed? Thanks so much :)

    Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

    S 1 Reply Last reply
    0
    • M misCafe

      Brothers, I've successfully coded to load data from db (sql server) to combobox in c sharp (ex: productname); but when I add new data to db (from c sharp), I want to add an pID of productname instead of the productname to db because I have two tables in db which have relationship together (ex: pID, productname) and (ex: cID, pID, qty, price). Lastly, I have another form to add more productname to db; so, how to refresh the combobox (as mentioned above) when this form is closed? Thanks so much :)

      Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

      S Offline
      S Offline
      Satish Pai
      wrote on last edited by
      #2

      Hi Chuon Visoth                      A Combobox as 2 properties Display Member & Value member. Assign "productname" as your Display member & "pID" as your value member. while saving data to your table assign value member. The "pID" & "productname" both columns should be in the query from which you assign it to commandText & then get Datatable Ex:- combobox1.DisplayMember = "productname"       comboBox1.ValueMember = "pID"             Thanks & Regards Satish Pai B

      S 1 Reply Last reply
      0
      • S Satish Pai

        Hi Chuon Visoth                      A Combobox as 2 properties Display Member & Value member. Assign "productname" as your Display member & "pID" as your value member. while saving data to your table assign value member. The "pID" & "productname" both columns should be in the query from which you assign it to commandText & then get Datatable Ex:- combobox1.DisplayMember = "productname"       comboBox1.ValueMember = "pID"             Thanks & Regards Satish Pai B

        S Offline
        S Offline
        ScottM1
        wrote on last edited by
        #3

        But this wouldn't refresh it, he would also have to update the DataTable that the combobox is bound to.

        M 1 Reply Last reply
        0
        • S ScottM1

          But this wouldn't refresh it, he would also have to update the DataTable that the combobox is bound to.

          M Offline
          M Offline
          misCafe
          wrote on last edited by
          #4

          Thanks for your support. I've found the way to load pID and productname; but my second question I've not found it yet. How to do that? HELP ... !

          Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

          S 1 Reply Last reply
          0
          • M misCafe

            Thanks for your support. I've found the way to load pID and productname; but my second question I've not found it yet. How to do that? HELP ... !

            Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

            S Offline
            S Offline
            ScottM1
            wrote on last edited by
            #5

            I would capture the closing event of the 2nd form from within your original form. http://www.codersource.net/csharp_delegates_events.html[^]

            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