none
HOw to bind ?

    Question

  • Hi

    Iam using c# windows application.

    I have 2 tables in sql server.
    in table 1 i have some fields called name,number,id,starttime,recuid
    and in table 2 i have field called recuid,address.

    i have a form in that i have a combo box and 4 txtboxex.

    my req is to bind the name field of table 1 to Combobox .
    number, id,starttime from table1 and Address from tabel2 to the Textboxes. so when ever the user select the names in the combobox automatically the txtboxes have to display it's purticuler information. I have done this for table 1 only. But i want to display the address also be changed with other textboxes. the condition is table1.recuid = table2.recuid.




    can anbdy help me??
    Tuesday, February 26, 2008 6:45 AM

Answers

  • Hi Srinivas Rejeti,

    The normal operation is to  set table1 unique column name to combobox ValueMember property and name column to DisplayMember property.

    Like code:

    Code Snippet

    this.comboBox1.DisplayMember = "table1namecolumn";

    this.comboBox1.ValueMember = "table1uniquecolumn";

    this.comboBox1.DataSource = ds;

     

     

     

    In the ComboBox SelectedIndexChanged event , you can search related data from table1, including recuid column value , then select address value from table2 with special recuid value.

     

    Best regards,

    Guang-Ming Bian - MSFT

    Thursday, February 28, 2008 2:48 AM
    Moderator

All replies

  • Hi Srinivas Rejeti,

    The normal operation is to  set table1 unique column name to combobox ValueMember property and name column to DisplayMember property.

    Like code:

    Code Snippet

    this.comboBox1.DisplayMember = "table1namecolumn";

    this.comboBox1.ValueMember = "table1uniquecolumn";

    this.comboBox1.DataSource = ds;

     

     

     

    In the ComboBox SelectedIndexChanged event , you can search related data from table1, including recuid column value , then select address value from table2 with special recuid value.

     

    Best regards,

    Guang-Ming Bian - MSFT

    Thursday, February 28, 2008 2:48 AM
    Moderator
  • Hi MR.Guang-Ming Bian.

     

    Thanks for your reply.

     

    If you don't mind could you explain briefly with a program.?

     

     

    Thanks and Regards, 

     

     

     

    Thursday, February 28, 2008 6:00 AM
  • Hi Srinivas Rejeti,

    Sorry for reply late, Please look at the sample:

    http://www.codeproject.com/KB/cs/combobox.aspx

     

     

    Best regards,

    Guang-Ming Bian - MSFT

    Monday, March 03, 2008 2:33 AM
    Moderator
  • Hi,

     

    Thanks for your reply.

     

    It is running ok for single table only. But my concern is to use this same way for 2 tables.

     

    as i told in my question,  i have to change the textbox value from the secondtable with the combobox changed item that belongs to first table.

     

    I have 4 txtboxes and 1 combobox. textbox 1,2,3 belongs to the 1st table, and txtbox4 belongs to the secondtable.

     

    i hav used one student name from the table1 that have been kept under the combobox. so, when ever the user selects one name then automatically 1st 3 txtboxs will show the corresponding values from the 1st table. But from second table i have a column as RECUID. This is table1.RECUID =  table2.RECUID. so when the user changes the name from the combobox, the txtbox4 will show the curresponding value since  table1.RECUID =  table2.RECUID.

     

     

    Can u plz tell me how to do this?

     

    ThankYou,

     

    Monday, March 03, 2008 4:12 AM