Click here to Skip to main content
15,911,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm trying to create a Select Distinct query, but i'm getting stuck with either an empy combobox either a filled combobox that displays all the doubles.

I have a form (form5) with 1 combobox and 1 datagrid.
The datagrid loads 5 collumns "ID", "firm", "Fname", "mname", "Lname"

The collumn "firm" will have some double firms with people in the other collumns

ID Firm Fname Mname Lname
1 AA John N West
2 AA Jim L East
3 BB Harry Sick Long
4 CC Barry N Klote

etc.
I would like to select the firm from a combobox and filter the datagrid so that it only displays the selected firm and the people that are registred here. Furthermore i want the combobox that i use for selecting the firms to lose the doubles.

I can load the datagrid and load the Combobox, but selecting is only pointing to the record (highlights in the grid) i choose and doesn't filter. Is there anyone that can give me a clue on how to solve this.

VB
Private Sub Form5_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Kjelpasser2012DataSet.Employees' table. You can move, or remove it, as needed.
        Me.EmployeesTableAdapter.Fill(Me.passer2012DataSet.Employees)
        'Select DISTINCT "firm" from "Employees" 
        'End Select

    End Sub

VB
  'TODO: This line of code loads data into the 'passer2012DataSet.Employees' table. You can move, or remove it, as needed.

        Dim ds As New passer2012DataSet
        Dim con As New OleDb.OleDbConnection
        Dim da As New OleDb.OleDbDataAdapter("Select DISTINCT firm from Employees", con)
        Dim dt As New DataTable
'i made these text
        'Me.passer2012DataSet.Employees.Open()
        ' da.Fill(ds)
        'dt = ds.Tables(0)

        'databinding()
        cmbfirma.DataSource = ds
        cmbfirma.DisplayMember = "employeeID" 'DataTextField = "employeeID"
        cmbfirma.ValueMember = "Firma" 'DataValueField = "Firma"
        Me.EmployeesTableAdapter.Fill(Me.Kjelpasser2012DataSet.Employees)
       
        con.Close()

Thank you for your reply. I don't seem to get i to work this way.

I use the "Me.EmployeesTableAdapter.Fill" method so is it possible that i don't need to use the OLEDB connection or do i still need this to correctly connect to the DB (access)? I changed a bit in the script you had sent but this did not do the trick. Any tips?

The combobox fills with the following text.

VB
System.Data.DataViewManagerListItemTypeDescriptor


what to do about this message?
Posted
Updated 4-Mar-12 23:29pm
v3
Comments
Cardin94 2-Mar-12 3:39am    
Can anyone shed more light on this for me?

1 solution

Try this one

VB
Dim ds As New DataSet()
Dim con As New OdbcConnection(ConnStr)
Dim da As New OdbcDataAdapter("Select DISTINCT firm from Employees", con)
con.Open()
da.Fill(ds)
dt = ds.Tables(0)

'databinding
dropdownlist.DataSource = ds
dropdownlist.DataTextField = "ID"
dropdownlist.DataValueField = "Firm"
dropdownlist.DataBind()


con.Close()


Best Regards,
@iamsupergrasya
 
Share this answer
 
Comments
Ganesan Natarajan 23-Feb-12 4:30am    
dropdownlist.DataTextField = "Firm"
dropdownlist.DataValueField = "ID"

and use the ID value to fetch the data
Cardin94 24-Feb-12 13:02pm    
<pre lang="vb">
'TODO: This line of code loads data into the 'passer2012DataSet.Employees' table. You can move, or remove it, as needed.

Dim ds As New passer2012DataSet
Dim con As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter("Select DISTINCT firm from Employees", con)
Dim dt As New DataTable
'i made these text
'Me.passer2012DataSet.Employees.Open()
' da.Fill(ds)
'dt = ds.Tables(0)

'databinding()
cmbfirma.DataSource = ds
cmbfirma.DisplayMember = "employeeID" 'DataTextField = "employeeID"
cmbfirma.ValueMember = "Firma" 'DataValueField = "Firma"
Me.EmployeesTableAdapter.Fill(Me.Kjelpasser2012DataSet.Employees)

con.Close()
</pre>
Thank you for your reply. I don't seem to get i to work this way.

I use the "Me.EmployeesTableAdapter.Fill" method so is it possible that i don't need to use the OLEDB connection or do i still need this to correctly connect to the DB (access)? I changed a bit in the script you had sent but this did not do the trick. Any tips?

The combobox fills with the following text.

Collapse | Copy Code
System.Data.DataViewManagerListItemTypeDescriptor
what to do about this message?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900