Home > Software engineering >  How to solve the multiple combo links database?
How to solve the multiple combo links database?

Time:09-16

I made a small dongdong doesn't know how is realized in a form three combo data link data table;
Name: (access2003 database Test
Combo1 link the first data table "doctor" inside "the doctor's name" list;
Combo2 link the inside of the second data table "department" "in the section" list;
Combo3 links the third data table "diagnosis treatment" in the "diagnosis" list;
Hope to lay the instructions, thank you

CodePudding user response:

The
refer to the original poster weixin_42195784 response:
I made a small east east don't know how to realized in a form three combo data link data table;
Name: (access2003 database Test
Combo1 link the first data table "doctor" inside "the doctor's name" list;
Combo2 link the inside of the second data table "department" "in the section" list;
Combo3 links the third data table "diagnosis treatment" in the "diagnosis" list;
Hope to lay the instructions, thank you

What do you use database, is basically the same, want to save trouble directly select * from doctor table, department table, diagnostic table, and then read the data to fill in it

CodePudding user response:

Link, form needs into adodc controls, set the adodc data connection properties,

Set the datasource combox to into the adodc controls, and set the datamember, datafield attribute, etc

CodePudding user response:

Use ADO, select three times, three times circulation to fill in three combo, individual does not recommend the use of the control function of data binding,

CodePudding user response:

Connection to omit,,,
Call OpenConn
SQL="select his doctor name from"
RSS. The Open SQL, cn, 1, 1
EOF
the Do While Not RSS.Combo1. AddItem RSS. Fields (" doctor's name "). The Value
RSS. MoveNext
Loop
Call CloseConn

CodePudding user response:

You actually and provinces, is a principle, and the code is easy to Google to provinces, linkage,

CodePudding user response:

 
Dim cn As New ADODB library. The Connection, the Rs As New ADODB. You

Private Sub Combo1_Click ()
Combo2. Clear
Call CONNDB (cn) 'database connection slightly
SQLX="Select * From Where the doctor Where departments='" & amp; Combo1. Text & amp; "'
"Rs. The Open SQLX, cn, 2, 1 'doctors and department linkage, different department, doctor's name in the drop-down box also different
EOF
the Do While Not Rs.Combo2 AddItem=Rs! The doctor's name
Rs. MoveNext
Loop
Rs. Close
Cn. Close
End Sub

Private Sub Form_Load ()
Combo1. Clear
Call CONNDB (cn) 'database connection slightly
SQLX="Select * From department", "
Rs. The Open SQLX, cn, 2, 1
EOF
the Do While Not Rs.Combo1 AddItem=Rs! Where the department
Rs. MoveNext
Loop
Rs. Close
'the third data table "diagnosis treatment of the" diagnosis "inside" not clear relationship with the doctor's name, don't know and is there a link between departments, if there is no relationship can:
Combo3. Clear
SQLX="Select * From diagnosis treatment"
Rs. The Open SQLX, cn, 2, 1
EOF
the Do While Not Rs.Combo3 AddItem=Rs! Diagnosis
Rs. MoveNext
Loop
Rs. Close
Cn. Close
End Sub

CodePudding user response:

'this article USES three adodc controls connect to the database
Private Sub Form_Load ()
'to connect to the database code omitted
Doctor Adodc1. RecordSource="select * from table"
Adodc1. Refresh
EOF=False Do While Adodc1. You.
Combo1. AddItem Adodc1. You (" the doctor's name ")
Adodc1. You. MoveNext
Loop
Adodc2. RecordSource="select * from department"
Adodc2. Refresh
EOF=False Do While Adodc2. You.
Combo2. AddItem Adodc2. You (" in the section ")
Adodc2. You. MoveNext
Loop
Adodc3. RecordSource="select * from diagnosis treatment"
Adodc3. Refresh
EOF=False Do While Adodc3. You.
Combo3. AddItem Adodc3. You (" diagnosis ")
Adodc3. You. MoveNext
Loop
End Sub

CodePudding user response:

As if you have a problem of the data table Settings, in fact, a data table to solve the problem, such as "doctors" data table, containing "the doctor's name" field, "in the section" fields, "diagnosis" fields, only need one Combo1 a drop-down box control, 2 Text1, Text2 control can be achieved, is the code below:
 
Private Sub Combo1_Click ()
Text1. Text=""
Text2. Text=""
'to connect to the database just
Rs. Open the "Select * From his doctor Where name='" & amp; Combo1. Text & amp; "'", CNN, 2, 2
Text1. Text=Rs! Where the department
Text2. Text=Rs! Diagnosis
Rs. Close
CNN. Close
End Sub

Private Sub Form_Load ()
Combo1. Clear
'to connect to the database just
Combo1. Clear
Rs. Open the "Select * From the doctor," CNN, 2, 2
EOF
the Do While Not Rs.Combo1. AddItem Rs (" doctor named ")
Rs. MoveNext
Loop
Rs. Close
CNN. Close
End Sub

In the doctor table data, storage "doctor's name" field, "in the section" fields, that the value of the "diagnosis" is ok,
  • Related