关于VB.NET多个combobox控件关联数据查询的有关问题

关于VB.NET多个combobox控件关联数据查询的问题
关于VB.NET多个combobox控件关联数据查询的有关问题


 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Conn As New OleDb.OleDbConnection
        Dim Comm As New OleDb.OleDbCommand
        Dim da As New OleDb.OleDbDataAdapter
        Dim ds As New DataSet

        Conn.ConnectionString = "provider=sqloledb;Data Source=S1;Initial Catalog=yz_jc;Persist Security Info=True;User ID=sa;Password=sa"
        Conn.Open()
        'MsgBox("连接成功", vbOKOnly + vbInformation, "测试连接")
        Comm.Connection = Conn
        Comm.CommandText = "select * from jcfl where area_parent=0 order by area_order"
        da = New OleDb.OleDbDataAdapter(Comm)
        da.Fill(ds, "jcfl")
        Conn.Close()
        ComboBox1.DataSource = ds.Tables(0)
        ComboBox1.DisplayMember = "area_name"
        ComboBox1.SelectedIndex = -1
    End Sub

上面是部分代码,我只实现了第一个数据查询,后面的请问要怎么做

Comm1.CommandText = "select * from jcfl where area_parent=" & ComboBox1.Text & " order by area_order"
------解决思路----------------------
从你连接语句看是sql:


        Dim Comm As New SqlClient.SqlCommand
        Dim da As New SqlClient.SqlDataAdapter
        Dim ds As New DataSet
        Dim Conn As New SqlClient.SqlConnection("Data Source=S1;Initial Catalog=yz_jc;User ID=sa;password=sa;Integrated Security=False")
        Conn.Open()
        Comm.Connection = Conn
        Comm.CommandText = "select top 10 * from where area_parent=0 order by area_order"
        da = New SqlClient.SqlDataAdapter(Comm)
        da.Fill(ds, "jcfl")
        DataGridView1.DataSource = ds.Tables(0).DefaultView
        Conn.Close()
        ComboBox1.DataSource = ds.Tables(0)
        ComboBox1.DisplayMember = "area_name"
        ComboBox1.SelectedIndex = -1
------解决思路----------------------
1、在ComboBox1_SelectedIndexChanged事件里写Comm1.CommandText = "select * from jcfl where xxx=" & ComboBox1.Text & " order by area_order" 
2、在ComboBox2_SelectedIndexChanged事件里写Comm2.CommandText = "select * from jcfl where xxx=" & ComboBox2.Text & " order by area_order" 
------解决思路----------------------
 Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim Comm As New SqlClient.SqlCommand
        Dim da As New SqlClient.SqlDataAdapter
        Dim ds As New DataSet
        Dim area_parent As Integer
        If ComboBox1.SelectedItem <> "" Then
            area_parent = Convert.ToInt16(ComboBox1.SelectedItem)
            sql = "select  * from jcfl where  area_parent=" & area_parent & "order by area_order"
        End If
        Dim Conn As New SqlClient.SqlConnection("Data Source=S1;Initial Catalog=yz_jc;User ID=sa;password=sa;Integrated Security=False")
        Conn.Open()
        Comm.Connection = Conn
        Comm.CommandText = sql
        da = New SqlClient.SqlDataAdapter(Comm)
        da.Fill(ds, "jcfl")
        DataGridView1.DataSource = ds.Tables(0).DefaultView
        Conn.Close()
        ComboBox2.DataSource = ds.Tables(0)
        ComboBox2.DisplayMember = "area_name"

    End Sub