Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a database table and it has some column with duplicate values , and i want to get that column value of the table in a combobox, but i want every value single time not repeatedly ... i tried but it is still giving me all values in the combobox:
VB
Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=grade;Integrated Security=True;Pooling=False")
Dim cmd As SqlCommand
Dim Classes As New List(Of String)
Try
    conn.Open()
    Dim query As String = "SELECT Class FROM Class"
    cmd = New SqlCommand(query, conn)
    Dim rd As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    While rd.Read()
        Classes.Add(rd("Class").ToString)
    End While
    rd.Close()
    conn.Close()

    Me.ComboClass.Items.Clear()
    Me.ComboClass.Items.AddRange(Classes.ToArray)

Catch ex As Exception
    MessageBox.Show(ex.ToString())


End Try
Posted

1 solution

SQL
SELECT DISTINCT Class FROM Class
 
Share this answer
 
Comments
ridoy 8-Nov-12 13:49pm    
+5
fjdiewornncalwe 8-Nov-12 13:59pm    
Thanks, ridoy
RaisKazi 8-Nov-12 13:51pm    
Simple short and correct. 5ed.
fjdiewornncalwe 8-Nov-12 13:59pm    
Thanks Rais

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900