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. combo box

combo box

Scheduled Pinned Locked Moved C#
csharpdatabasequestion
3 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.
  • K Offline
    K Offline
    kirandilip
    wrote on last edited by
    #1

    good morning, i create a table employee,in that table i have two columns empid,empname.i can create a form inthat i can use combo box and text box,combobox contains empid,id,if i can select a empid from the combobox the corresponding empname in the database that displays on the textbox.how can we do that?give me a better solution. thank u.(using ado.net & c#.net)

    B N 2 Replies Last reply
    0
    • K kirandilip

      good morning, i create a table employee,in that table i have two columns empid,empname.i can create a form inthat i can use combo box and text box,combobox contains empid,id,if i can select a empid from the combobox the corresponding empname in the database that displays on the textbox.how can we do that?give me a better solution. thank u.(using ado.net & c#.net)

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

      Hi Here's my suggestion.Having a service that returns an EmployeeName by a given EmployeeId, you can ask for EmployeeName by employeeId whenever you want. First I create an Interface: public interface IEmployeeService { string GetEmployeeNameById(int emp_id); } Then I implement it.According to your scenario I think that you can get an employee name when its needed(you don't have to load all names at once) Here's a possible implementation: public string GetEmployeeNameById(int emp_id) { var query=string.Format("SELECT emp_name FROM EmployeeTable WHERE emp_id={0}",empId); //Execute a database command and return its result ... } Now I define a local variable in my form like this: ... IEmployeeService employeeService=new MyEmployeeSrvice(); ... And finally I handle the ComboBox SelectedItemChange event to set text of EmployeeName text box ... empNameTextBox.Text=employeeService.GetEmployeeNameById(selectedId); ...

      1 Reply Last reply
      0
      • K kirandilip

        good morning, i create a table employee,in that table i have two columns empid,empname.i can create a form inthat i can use combo box and text box,combobox contains empid,id,if i can select a empid from the combobox the corresponding empname in the database that displays on the textbox.how can we do that?give me a better solution. thank u.(using ado.net & c#.net)

        N Offline
        N Offline
        nelsonpaixao
        wrote on last edited by
        #3

        do like post above. remember that you dont edit the combobox, you edit the dataset the fill the combobox. i do that in sql server, you can do it as well.

        nelsonpaixao@yahoo.com.br trying to help & get help

        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