用VB编写SQL查询

时间:2013-03-19 01:22:12

标签: sql vb.net

我正在尝试在颜色列中显示值列表,但是当我单击按钮时它只给我一个值

Imports System.Data
Imports System.Data.OleDb

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ''TODO: This line of code loads data into the '''AdventureWorksLTDataSet.Product' table. You can move, or remove it, as needed.
        Me.ProductTableAdapter.Fill(Me.AdventureWorksLTDataSet.Product)

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim conDB As New OleDb.OleDbConnection
        conDB.ConnectionString = "....."
        Dim comDB As New OleDb.OleDbCommand
        Dim dbrDB As OleDbDataReader
        Dim SQLQuery As String

        conDB.Open()
        comDB.Connection = conDB
        SQLQuery = "SELECT DISTINCT P.color FROM SalesLT.Product P WHERE P.color is not NULL"
        comDB.CommandText = SQLQuery
        dbrDB = comDB.ExecuteReader()



        If (dbrDB.Read) Then
            While dbrDB.Read       ' 'cycle through resulting tuples
                Label1.Text = dbrDB("color")
            End While
        End If



    End Sub
End Class

1 个答案:

答案 0 :(得分:4)

每次循环时,您都会覆盖标签值,可能需要这样:

Label1.Text = Label1.Text + "," + dbrDB("color")