hi

hi ..

how can i fill the items of the combobox from the data base

4 exapmle :

table students include a name lets say jim & bill so the combo box should display jim and bill if i add new student peter then the combo box should display the all three students

thx



Answer this question

hi

  • James Nachbar

    No, but "Name" needs to be the name of a column in your table, or you need to change it. What's the code/exact error



  • Braian

    How about using the ComboBox.DataSource property

    ____
    http://www.peterRitchie.com/blog/



  • tinytee

    >> cuz im new in C# and i dont know how 2 use it.

    Before I do, can I just say that if you're unable to work out how to do it based on my advice, you would do better to write console apps for a bit, and work through a book so you actually learn C#, instead of just learning to ask for example code here.

    Assuming that you have a DataTable called dt, which contains a column called 'Name', and a combobox called c.

    c.DataSource = dt;

    c.DisplayMember = "Name";

    Naturally, your variables should have more descriptive names.

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/vbcon/html/vbtskdatabindingcomboboxcheckedlistboxorlistboxcontrol.asp



  • Andy Lindley

    You can request the data from the database, and set the datatable to be the datasource. Then there's a displaymember property you can set to tell the combobox what column to read the data from. There's also a valuemember property, or similar, which sets the value, such as an ID, to associate with each display value.



  • PascalJC

    hi

    can any1 give me a code plz

    cuz im new in C# and i dont know how 2 use it.

    thx


  • Thomas2054

    hi ,

    i tried this code but i still got 1 error , the error is my tables name the error says its not exisit , do i need 2 include anything

    thx


  • hi