Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent Duplication within a dataset

Status
Not open for further replies.

cschristian78

Technical User
Nov 3, 2004
23
0
0
US
I have a group of results in a sql database (in one table named [zz_Results Master]. This table has mulitple colums - in particular [Set] and [Type]. The set is a user defined name that describes a set of sql queries. The type describes what type of queries were run. So for example, I will have a set named Set1 in the [Set] field and then I may have many types of queries such as State, County, Countries, etc. Each query will list the number of locations and sum the values. I am creating a results viewer so that the user can see results based on the set and type of queries. The problem is that when I set the combo box that lists the types of queries, it contains duplicate values. For example, when selecing the combo box, I might have the following:

State
State
Country
County
County
County...etc. Is there a way to group the "DisplayMember" property? Here is the code below.

Private Sub btnLP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLP.Click

daResults.SelectCommand = New SqlClient.SqlCommand("Select * from [zz_Results Master]", ProfDataCon)

Try
daResults.Fill(dsResults, "dtLP")
cmbProfile.DataSource = dsResults.Tables("dtLP")
cmbProfile.DisplayMember = "Type".ToString
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

End Sub
 
this seems very odd to me why not make another table with this as the query

Code:
select distinct [type] from [zz_results master]

and bind that to your combobox.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
That seems to work fine - thanks. The problem I am having now is how to allow two combo boxes that have the same datasource be able to choose different rows of that dataset. For example, I have a dataset called dsResults and I fill the datatable "dtLP" with the select statement below. I populate my list which is then past to both combo boxes. From here, I want the ability to select different items in the list. Here is my code and thanks again for the help.

Private Sub btnLP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLP.Click
daResults.SelectCommand = New SqlClient.SqlCommand("Select distinct [Set] from [zz_Results Master] order by [set]", ProfDataCon)
Try
daResults.Fill(dsResults, "dtLP")
cmbSet1.DataSource = dsResults.Tables("dtLP")
cmbSet1.DisplayMember = "Set"
cmbSet2.DataSource = dsResults.Tables("dtLP")
cmbSet2.DisplayMember = "Set"
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top