Public Class Form2
Dim clsdb As New database
Sub province1()
Dim prosql As String = "select * from Province "
Dim ds As DataSet
ds = clsdb.querydataset(prosql)
With ComboBox2
.DisplayMember = "provincename"
.ValueMember = "provinceid"
.DataSource = ds.Tables(0)
'.SelectionStart = 0
.Text = "กรุณาเลือก"
End With
End Sub
Sub province2()
Dim prosql As String = "select * from Province "
Dim ds As DataSet
ds = clsdb.querydataset(prosql)
With ComboBox5
.DisplayMember = "provincename"
.ValueMember = "provinceid"
.DataSource = ds.Tables(0)
'.SelectionStart = 0
.Text = "กรุณาเลือก"
End With
End Sub
Sub area1()
ComboBox3.Text = ""
Dim arsql1 As String = "select * from area,province where area.provinecid=province.provinceid and area.provinceid='" & ComboBox2.SelectedValue & "' "
Dim ds1 As DataSet
ds1 = clsdb.querydataset(arsql1)
With ComboBox3
.DisplayMember = "areaname"
.ValueMember = "areaid"
.DataSource = ds1.Tables(0)
'.SelectionStart = 0
.Text = "กรุณาเลือก"
End With
End Sub
Sub area2()
Dim arsql2 As String = "select * from area,province where area.provinecid=province.provinceid and area.provinceid='" & ComboBox5.SelectedValue & "' "
Dim ds2 As DataSet
ds2 = clsdb.querydataset(arsql2)
With ComboBox6
.DisplayMember = "areaname"
.ValueMember = "areaid"
.DataSource = ds2.Tables(0)
'.SelectionStart = 0
.Text = "กรุณาเลือก"
End With
End Sub
Sub zone1()
Dim zsql As String = "select * from zone,area where zone.areaid=area.areaid and zone.areaid='" & ComboBox3.SelectedValue & "' "
Dim ds As DataSet
ds = clsdb.querydataset(zsql)
With ComboBox4
.DisplayMember = "zonename"
.ValueMember = "zoneid"
.DataSource = ds.Tables(0)
'.SelectionStart = 0
.Text = "กรุณาเลือก"
End With
End Sub
Sub zone2()
Dim zsql As String = "select * from zone,area where zone.areaid=area.areaid and zone.areaid='" & ComboBox6.SelectedValue & "' "
Dim ds As DataSet
ds = clsdb.querydataset(zsql)
With ComboBox7
.DisplayMember = "zonename"
.ValueMember = "zoneid"
.DataSource = ds.Tables(0)
'.SelectionStart = 0
.Text = "กรุณาเลือก"
End With
End Sub
'**************************************************************************************************************
'**************************************************************************************************************
'**************************************************************************************************************
'**************************************************************************************************************
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = DateAndTime.Now
Button3.Visible = False
Button4.Visible = False
province1()
province2()
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim arsql1 As String = "select * from area,province where area.provinceid='" & ComboBox2.SelectedValue & "' and area.provinecid=province.provinceid "
Dim ds1 As DataSet
ds1 = clsdb.querydataset(arsql1)
With ComboBox3
.DisplayMember = "areaname"
.ValueMember = "areaid"
.DataSource = ds1.Tables(0)
'.SelectionStart = 0
.Text = "กรุณาเลือก"
End With
End Sub
End Class
ผมลองเปลียนจาก combobox2 มาเป็น combobox3 มันเออเรอแจ้งว่า "No value given for one or more required parameters."
ผมก็เลยงงอยู่ว่ามันเออเรอเพราะอะไร ทำไมมันบอกว่าตัวแปรไม่มีค่า