السلام عليكم ورحمة الله وبركاته
تفضل بعد عمل قاعدة بيانات حسب الهيكلية التي في بداية الكود (مجرب بنجاح في مثال سابق لدي)
PHP كود :
Public Class Form1
'' Database:
'' Country: id, name
'' State : id, name, CountryId
'' City : id, name, CountryId, StateID
Private connection As New SqlClient.SqlConnection("Data Source=.\SQLEXP; Initial Catalog=SGG; Integrated Security=True")
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ComboBoxFill(Me.ComboBox1, "[Country]")
End Sub
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
ComboBoxFill(Me.ComboBox2, "[State]", "[CountryID] = " & ComboBox1.SelectedValue)
End Sub
Private Sub ComboBox2_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectionChangeCommitted
ComboBoxFill(Me.ComboBox3, "[City]", "[CountryID] = " & ComboBox1.SelectedValue & " AND [StateID] = " & ComboBox2.SelectedValue)
End Sub
Private Sub ComboBox3_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectionChangeCommitted
Me.TextBox1.Text = Me.ComboBox1.Text & ", " & Me.ComboBox2.Text & ", " & Me.ComboBox3.Text
End Sub
Sub ComboBoxFill(ByVal combobox As ComboBox, ByVal tablename As String, Optional ByVal condition As String = "")
Dim sql As String = "SELECT * FROM " & tablename
If condition.Trim <> "" Then
sql &= " WHERE " & condition
End If
Dim adapter As New SqlClient.SqlDataAdapter(sql, connection)
Dim table As New DataTable
adapter.Fill(table)
combobox.DataSource = table
combobox.ValueMember = "id"
combobox.DisplayMember = "Name"
combobox.SelectedIndex = -1
End Sub
End Class
السلام عليكم ورحمة الله وبركاته
