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:
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:
<pre lang="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
</pre>