Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 7: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 at 8-Nov-12 13:49pm
   
+5
Marcus Kramer at 8-Nov-12 13:59pm
   
Thanks, ridoy
RaisKazi at 8-Nov-12 13:51pm
   
Simple short and correct. 5ed.
Marcus Kramer at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2014
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