Click here to Skip to main content
13,295,192 members (68,781 online)
Rate this:
 
Please Sign up or sign in to vote.
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:
        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 8-Nov-12 8:44am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

SELECT DISTINCT Class FROM Class
  Permalink  
Comments
ridoy 8-Nov-12 13:49pm
   
+5
Marcus Kramer 8-Nov-12 13:59pm
   
Thanks, ridoy
RaisKazi 8-Nov-12 13:51pm
   
Simple short and correct. 5ed.
Marcus Kramer 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
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100