0

我想在一个组合框中显示特定列中的所有数据,而我的代码只是显示列中的最后一个数据,这是我正在使用的代码

Dim connectionstring As String = "Data Source=localhost\SQLEXPRESS;InitialCatalog=Enginee;Integrated Security=True"

Try
        Dim connection As New SqlClient.SqlConnection(ConnectionString)
        Dim sqlquery As String
        connection.Open()
        MessageBox.Show("Open")
        sqlquery = " Select PROJECT.PROJECT_CODE,PROJECT.PROJECT_NAME From PROJECT INNER JOIN ENGINEERS on ENGINEERS.ENGINEER_ID = ENGINEERS.ENGINEER_ID where ENGINEERS.FNAME = '" & Sign_In.TextBox1.Text & "' "

        Dim selectcommand As New SqlClient.SqlCommand(sqlquery, connection)
        Dim reader As SqlClient.SqlDataReader = selectcommand.ExecuteReader
        Dim test As Boolean = reader.Read

        While test = True
            ComboBox1.Text = reader(0)
            TextBox1.Text = reader(1)
            test = reader.Read
        End While
    Catch ex As Exception
        MessageBox.Show("Failed")
    End Try
4

1 回答 1

2

而不是设置 ComboBox 的 .text 添加项目。

ComboBox1.Items.Add(reader(0));

设置文本值只会设置当前项目是什么,而不是将它们添加到下拉列表中。

于 2013-09-25T11:33:52.167 回答