Using MS-Access as a database (since you did not mention your data provider) using an OleDbConnection and OleDbCommand to load data into a DataTable, create a view (see below) which returns distinct values for a field from a database table.
Our intial SQL (returned via an OleDbCommand) into a DataTable
Code:
SELECT
Identifer,
CompanyName,
ContactName,
ContactTitle,
Address,
City,
PostalCode,
Country
FROM Customer
Here is a simple example
Code:
Public Sub SimpleDemo()
Using cn As New OleDbConnection("Your connection string")
Dim cmd As OleDbCommand = New OleDbCommand
cmd.Connection = cn
cmd.CommandText = _
<SQL>
SELECT
Identifier,
CompanyName,
ContactName,
ContactTitle,
Address,
City,
PostalCode,
Country
FROM Customer
</SQL>.Value
Dim dt As New DataTable With {.TableName = "Customers"}
cn.Open()
dt.Load(cmd.ExecuteReader())
Dim DistinctCompanies = _
New DataView( _
dt.DefaultView _
.ToTable("Companies", True, "CompanyName"))
End Using
End Sub
Now dt has all fields and rows while DistinctCompanies has Distinct companies but having just the company names does not do much good unless we can have a pointer back to the database or the other data table so let's add the primary key
Code:
Dim ColNames() As String = {"Identifier", "CompanyName"}
Dim DistinctCompanies = _
New DataView( _
dt.DefaultView _
.ToTable("Companies", True, ColNames))
In the ComboBox Identifier becomes the ValueMember, CompanyName the DisplayMember and DistinctCompanies the data source.
Code:
ComboBox1.DisplayMember = "CompanyName"
ComboBox1.ValueMember = "Identifier"
ComboBox1.DataSource = DistinctCompanies