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

[234 byte] By [Socal5vee] at [2007-12-25]
# 1

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

spotty at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2
I'm trying to get the values in my combo box to show only once instead of showing the same value 10 or 20 times. I know that i need to use the SELECT DISTINCT query, i've used this query before in Access 2003, i inserted the query into the row source. I have an Access database linked to my project. I have dragged a Table into my form using the dataview and now want to use a combo box with one of the fields using the SELECT DISTINCT query to show values in that field only once. How and where do I use this query?
Socal5vee at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

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.

spotty at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4
This looks like the answer to one of my questions but im not sure I understand how to execute it... WHere do you place the select statement?
KellyR.Martin at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5

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.

spotty at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 6
I have read thorugh a pile of documents on it but I am still missing how to implement it.
KellyR.Martin at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 7
Ok. Im a little closer now. The only problem is to get the box to become distinct i need to click a fillby button. Is there a way it is automaticly distinct? do i write the sql statement into code somehow?
KellyR.Martin at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...