通过combobox1的选择筛选combobox2的内容?
举个例子说一下,combobox1连接的是access数据库中一个表的“省份”,combobox2连接的是access数据库中同一个表的“城市”,通过选择combobox1的省份,例如:山东,combobox2下拉表的内容就只是山东的城市,我在combobox2连接的适配器的查询器里编写了select distinct 城市 from table where 省份= '+trim(combobox1.text)+ ',程序表示无法识别,但编写了select distinct 城市 from table where 省份= '山东 '就可以了,请求各位高手支招!谢谢了
[解决办法]
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim cmd As New SqlCommand( "select distinct 城市 from table where 省份= '+trim(combobox1.text)+ ' ", SqlConnection1)
Dim da As New SqlDataAdapter(cmd)
SqlConnection1.Open()
Dim ds As New DataSet
da.Fill(ds)
ComboBox2.DisplayMember = "城市 "
ComboBox2.ValueMember = "城市 "
ComboBox2.DataSource = ds.Tables(0)
End Sub