input data to a combobox or textbox and display to another

elvato

New member
Joined
Jan 20, 2006
Messages
4
Programming Experience
1-3
HI, I want to know how can I do the following:

1.- I have a database with different tables:
-employees (the "master table") it has empID, name and date of birth.
-address (empid, address, numer, etc etc)
-family (empid, name, date of birth, and family relation(mother, wife, etc))
-additional (empid, departament, date(of contract sing), date(of contract end)

as you can see they all have the empid field, and the relationship is with that field. the family table can have repeated empid cause it adds a record for each member of his/her family.

now, i have a new table where I have to add some fields from those tables
but i don't want to type the data again so, I want to make in my form, for example...

- a combobox1 with the empid from the employees table added as the items for that combobox

dim orow as datarow
For Each oRow In dsCodeTables.Tables("employees").Rows
combobox1.Items.Add(oRow("empid").ToString())

now, here comes the part that I can't do...
Now when I select the empid from the combobox, i want to fill another combobox2 with the NAME of the "family" table, but only the ones that have the same EMPID that the one in the combobox1

Also, do the same thing with the "address" table putting the address and number fields on textboxes (text1 and text2), but i want to put the ones that match the empid from the combobox1...

any help?

I was making an example using a textbox to put the empid, and, when pressing enter it showed something on another textbox:

Private Sub txtField1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtField1.KeyDown
Dim data As New r
Dim aux As Object
Dim aux2 As String
If e.KeyCode = 13 Then
aux = txtField1.Text
aux2 = "here I know I have to make a sql query like "SELECT * FROM family WHERE empid IS LIKE....."
txtField2.Text = aux2
End If
End Sub

I think thats how i have to do it, but i don't know how to make the sqlquery, or select the right empid, well, anythig...

Thanx for the help
 
Hello,

U can do following two things:

While retrievin the data from ur database just specify the join query between ur master tables n other tables:

Select * from Emloyee e, Family f Where e.empid=f.empid

n then fill the datatable using the adapter.

Otherwise just fill ur dataset with all the four tables n then define a relation between them using the datarelation object. For this refer to msdn.

Once u r through with the above process just show the records in ur text boxes n combo boxes based on the selected employee id.

comboEmployee.datasource=tableEmpl
comboEmployee.displaymember="EmployeeID"

comboFamily.datasource="Name of the Child Table"
comboFamily.displaymember="Name of the Column"

Chills
 
Back
Top