Private Sub ComboBox_Region_Amphur_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox_Region_Amphur.SelectedIndexChanged
ComboBox_Province.Enabled = True
Dim cmds As New SqlCommand
Dim sqlC As String = ""
Dim dd As SqlDataReader
conn.Close()
sqlC &= "select Province_Name from P_D_Province where Region_ID = (select Region_ID from P_D_Region where Region_Name = '" & ComboBox_Region_Amphur.Text & "'"
ComboBox_Province.Items.Clear()
With cmds
conn.Open()
.CommandType = CommandType.Text
.CommandText = sqlC
.Connection = conn
dd = .ExecuteReader()
While dd.Read()
ComboBox_Province.Items.Add(dd.GetString(0))
End While
End With
dd.Close()
End Sub
Tag : .NET, Ms SQL Server 2008, VB.NET, VS 2008 (.NET 3.x)
dim con as new connection
dim cm as sqlcommand
dim rs as sqldatareader
dim str as string
str ="SELECT item FROM ITEM"
con.connect
cm = new sqlcommand(str,connect)
rs = cm.executereader
while rs.read
combobox.item.add(rs("item"))
end while
con.close