08-12-21, 04:42 PM
كود :
Imports System.Data.OleDb
Public Class Form1
Dim conne As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Database1.mdb"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
fill_father_name()
End Sub
Private Sub fill_father_name()
Dim SQL As String = "SELECT Fathercode , Fathername From TableFather"
Dim da As New OleDbDataAdapter(SQL, conne)
Dim ds As New DataSet
da.Fill(ds, "TableFather")
ComboBox1.DataSource = ds.Tables("TableFather")
ComboBox1.DisplayMember = "Fathername"
ComboBox1.ValueMember = "Fathercode"
ComboBox1.SelectedIndex = -1
End Sub
Private Sub fill_student_name()
Dim SQL As String = "SELECT studentname , studentfathercode From TableStudent Where studentfathercode = '" & ComboBox1.SelectedValue & "'"
Dim da As New OleDbDataAdapter(SQL, conne)
Dim ds As New DataSet
da.Fill(ds, "TableStudent")
ComboBox2.DataSource = ds.Tables("TableStudent")
ComboBox2.DisplayMember = "studentname"
ComboBox2.ValueMember = "studentfathercode"
End Sub
Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
fill_student_name()
End Sub
End Class