Private Sub comboprovince()
Dim conn As New SqlConnection
Dim strcon As String = "Data Source=KAN-PC;Initial Catalog=master;Integrated Security=True"
If conn.State = ConnectionState.Open Then conn.Close()
conn.ConnectionString = strcon
conn.Open()
Dim sql As String = "SELECT id_province,province FROM province Order by province"
Dim da As New SqlDataAdapter(sql, conn)
Dim dt As New DataTable
da.Fill(dt)
With cbprovince
For i = 0 To dt.Rows.Count() - 1
.DataSource = dt
.DisplayMember = dt.Columns.Item("province").ColumnName 'คือตัวที่ใช้แสดงใน Combobox
.ValueMember = dt.Columns.Item("id_province").ColumnName 'Code หรือรหัสที่เราสร้างขึ้นมาเช่น Primary Key
Next
End With
End Sub
Private Sub call_distict()
Dim conn As New SqlConnection
Dim strcon As String = "Data Source=KAN-PC;Initial Catalog=master;Integrated Security=True"
If conn.State = ConnectionState.Open Then conn.Close()
conn.ConnectionString = strcon
conn.Open()
Dim sql As String = "SELECT id_district,district FROM district order by district"
Dim da As New SqlDataAdapter(sql, conn)
Dim dt As New DataTable
da.Fill(dt)
Try
With cbdistrict
.DataSource = dt
.DisplayMember = dt.Columns.Item("district").ColumnName
'คือตัวที่ใช้แสดงใน Combobox
.ValueMember = dt.Columns.Item("id_district").ColumnName 'Code หรือรหัสที่เราสร้างขึ้นมาเช่น Primary Key
End With
Catch ex As Exception
cbdistrict.Text = Nothing
End Try
End Sub
Private Sub cbprovince_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbprovince.SelectedValueChanged
call_distict()
End Sub