使用vb.net

时间:2017-03-09 08:55:57

标签: sql-server vb.net datagridcomboboxcolumn

我有一个普通的组合框和一个datagrid组合框,当我选择一个普通组合框中的特定项目时,我希望它的相关项目显示在datagrid组合框中。它运作良好。但是当我更改普通组合框中的项目时,datagrid组合框中的项目会被添加到之前的项目中,但我希望它被重置。

     Private Sub cmbGroupId_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbGroupId.SelectedIndexChanged
    Dim con As New SqlConnection
    con.Open()
    Dim theQuery2 As String = "select [GroupName] from [RuralDevelopmentProject].[dbo].[Groups] WHERE GroupID='" + cmbGroupId.Text + "'"
    Dim cmd2 As SqlCommand = New SqlCommand(theQuery2, con)
    Dim str As String = cmd2.ExecuteScalar()
    txtGroupName.Text = str
    cmd2.Dispose()

    Dim theQuery3 As String = "select [MemberName] from [RuralDevelopmentProject].[dbo].[Member] WHERE GroupID='" + cmbGroupId.Text + "'"
    Dim cmd3 As SqlCommand = New SqlCommand(theQuery3, con)
    Dim dr3 As SqlDataReader = cmd3.ExecuteReader()
    While dr3.Read()
        ShortName.Items.Add(dr3(0).ToString)
    End While
    dr3.Close()
    cmd3.Dispose()
    con.Close()
End Sub

0 个答案:

没有答案