I'm trying to create a Select Distinct query, but i'm getting stuck with either an empty combobox either a filled combobox that displays all the doubles.
or a message "System.Data.DataViewManagerListItemTypeDescriptor"

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 chooses but doesn't filter. Is there anyone that can give me a clue on how to solve this.

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  
 Collapse | Copy Code  
  '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 this 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.passer2012DataSet.Employees)  

        con.Close()

I use the "Me.EmployeesTableAdapter.Fill" method so mu question is, 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 the script that i brewed together as displayed above, but this did not do the trick.

The combobox fills with the following text.

System.Data.DataViewManagerListItemTypeDescriptor

or
is empty
or shows the doubles.

Is there anyone that can help me solve this last piece of my puzzle?

Recommended Answers

All 7 Replies

well , simple you have to change the query like this

Dim da As New OleDb.OleDbDataAdapter("Select DISTINCT firm from Employees where firm='"& combobox1.text &"'", con)

use this , then your grid will only show the records of selected firm , now you have to use oledb connection in order to perform any db function , insertion , updation , delete , search , etc , so it is imp.

Regards

That is what i call a quick reply. Thank you for that.

I understand i need to use the oledb for this it can be done directly.
I will do this and come back to inform on the results.

I get an error message on this.

Private Sub Form5_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'passer2012DataSet.Employees' table. You can move, or remove it, as needed.

        Dim ds As New DataSet
        Dim con As New OleDb.OleDbConnection
        Dim da As New OleDb.OleDbDataAdapter("Select DISTINCT firm from Employees where firm='" & cmbfirma.Text & "'", con)
        Dim dt As New DataTable
        con.ConnectionString = "PROVIDER= Microsoft.Jet.OLEDB.4.0;data source = C:\temp\VBtest\Projects\testing\WindowsApplication2\WindowsApplication2\passer2012.mdb"
        'New DataSet 'New passer2012DataSet
        con.Open()
        da.Fill(ds, "employeeID")
        dt = ds.Tables(0)

        'databinding()
        cmbfirma.DataSource = ds 'Me.passer2012DataSet.Employees
        cmbfirma.DisplayMember = "employeeID"
        cmbfirma.ValueMember = "Firma"

        con.Close()

    End Sub

Get the error on the following line

da.Fill(ds, "employeeID")

Says he lack some parameters here. can't figure out this part.

Is there anyone that can give me a tip on this error?
da.fill should mean that he needs to open the dataadapter and fills it with the dataset or am i wrong. I thought that i covered all there.

please change this code

'New DataSet 'New passer2012DataSet
        con.Open()
        da.Fill(ds, "employeeID")
        dt = ds.Tables(0)

        'databinding()
        cmbfirma.DataSource = ds 'Me.passer2012DataSet.Employees

with this

'New DataSet 'New passer2012DataSet
        con.Open()
ds.tables("employeeID").clear()
        da.Fill(ds, "employeeID")
        
        'databinding()
        cmbfirma.DataSource = ds.table("employeeID")

it will work fine :)

Regards

Hmmm, tried this, but still an error :-(

ds.Tables("employeeid").Clear()

"Object reference not set to an instance of an object."

Any tips regarding this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.