By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,505 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,505 IT Pros & Developers. It's quick & easy.

Bindingsource Filter with multiple values

P: 1
I have a junction table for instance 1 service can have many contacts - using a composite key junction table.

what i want to do is to filter all the contacts that belong to the service using the junction table that includes just PK to service and PK to contact as a composite key.

I used this code

Expand|Select|Wrap|Line Numbers
  1.  'set up the agency binding source
  2.             With serviceBindingSource
  3.                 .DataSource = aDataSet
  4.                 .DataMember = "Service"
  5.                 .Filter = "Agency_ID = " & CInt(CurrentAgencyID)
  6.             End With
  7.  
  8.             'set up the offer binding source
  9.             With offerBindingSource
  10.                 .DataSource = aDataSet
  11.                 .DataMember = "Offer"
  12.                 .Filter = "Service_ID = " & Me.serviceBindingSource.Current("Service_ID").ToString
  13.             End With
  14.  
  15.             'set up the contactbinding source
  16.             With contactBindingSource
  17.                 .DataSource = aDataSet
  18.                 .DataMember = "Contact"
  19.                 .Filter = "Contact_ID = " + offerBindingSource.Current("Contact_ID").ToString
  20.             End With
  21.  
  22.             With Me.cboContact
  23.                 .DataSource = contactBindingSource
  24.                 .DisplayMember = "C_Name"
  25.                 .ValueMember = "Contact_ID"
  26.                 .DataBindings.Add("text", contactBindingSource, "C_Name", False, DataSourceUpdateMode.Never)
  27.             End With
  28.  
The problem is i get all the contact ids that are in the junction table for instance 3 then i want to filter those 3 contact ids in the contact bindingsource.

This seems to work with the = but it only filters the first record it finds in the junction table not all the "3" records that belong.

I tried using the IN but it still does the same thing.

Is there a way to use a for next to filter it to how many records of contacts belong to the services using the junction table that has a composite key for contact_id and services_id.

any help is appreciated

Okay its fixed

Expand|Select|Wrap|Line Numbers
  1. If offerBindingSource.Count <> 0 Then
  2.             'genius at work
  3.             Me.offerBindingSource.MoveFirst()
  4.             Dim count As Integer = Me.offerBindingSource.Count
  5.             count -= 1
  6.             'Dim IDArray(count) As String
  7.             Dim query As String = ""
  8.             For i As Integer = 0 To count
  9.                 query += "'" + Me.offerBindingSource.Current("Contact_ID").ToString + "'"
  10.                 If i <> count Then
  11.                     query += ","
  12.                 End If
  13.                 Me.offerBindingSource.MoveNext()
  14.             Next
  15.             contactBindingSource.Filter = "Contact_ID IN (" + query + ")"
  16.         End If
  17.  
pretty much had to think like a genius
Sep 23 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.