combo box
Hi,
I'm trying to use the SELECT DISTINCT Query in combo box in a form i've created by draging the table in data grid view......where do i put this query at..........is it somewhere in the edit column area?
Thanks
Hi,
I'm trying to use the SELECT DISTINCT Query in combo box in a form i've created by draging the table in data grid view......where do i put this query at..........is it somewhere in the edit column area?
Thanks
You'll need to provide a bit more of a description about what you are trying to achieve.
Do you want to show only distinct values in a combobox ?
Is the combobox in the datagridview ?
Provide as detail a description on what you are trying to achieve and you'll likely get more assistance
You have two options here
If you havent yet picked up the data from the database then you can use a distinct keyword in you SQL statement
Select distinct name from Customers
This will result in only distinct names from the customers table being returned to a dataset which you can then use to bind to you combobox.
If you already have the dataset but only want to show distinct values then you can create a new datatable (which you can bind to ) with only the distinct values using something like the following which will create a datatable called d3 containing only distinct values for the city field from a datatable called dt
Dim d3 As DataTable = dt.DefaultView.ToTable(True, "City")
To create a new datatable which is based upon the Unique city fields in a datatable called dt.
The result is a datatable called d3 which contains only unique city fields and which you can then use for you databinding by setting as the datasource property of the combobox.
If you are in the process of retrieving data from a database there will be a select command use to determine which records to retrieve.
This may well be created automatically for you - if you use the wizard in order to create the data access objects. If you looking the dataset designer at the table adapter select command property there is a SQL Statement there.
Otherwise if you use ADO.NET to populate you dataset then there is a CommandText property on the ADO.NET SQLCommand Class.
So it depends upon how you are populating your dataset.
Do a search on either databinding and VB.NET and/or ADO.NET and VB.NET and you'll find numerous article about populating up datasets.