2013-09-25 122 views
0

我要显示在一个组合框在一个特定的列中的所有数据和我的代码只是显示在这里列的最后一个数据的SQL coulmn数据是我使用显示在vb.net组合框

代码
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 
+0

使用此ComboBox1.Items.Add(reader(0).ToString())而不是ComboBox1.Text。 – MMK

回答

2

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

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

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