Avatar of roarteam
roarteam
 asked on

VB.NET bindingsource.find not working

This is a second part to https://www.experts-exchange.com/questions/26616925/OPening-a-form-and-passing-data-from-datagrid-in-VB-NET.html?anchorAnswerId=34147039#a34147039

I have a form that opens with a bindingsource on it and I want to set it to a particular record.  In the form, I have the following:
 
Public Sub New(ByVal idNum As Integer)
        InitializeComponent()
        Debug.WriteLine("ID passed = " & idNum)
        Dim row As Integer
        row = CustomerTBLBindingSource.Find("CustomerID", row)        
        Debug.WriteLine("Index=" & row)
        If row <> -1 Then
            CustomerTBLBindingSource.Position = row
        End If

Open in new window


I can't get the find to work for the life of me!  The table has 3 records with CustomerIDs of 1,2 and 3.  The field is set to the primary key with a value of int.  I even tried:

    row = CustomerTBLBindingSource.Find("LastName", "Bob")

Where one of the records has Bob for the LastName, but it always returns an index of -1.  I have found all kinds of examples identical to this and they seem to work for everyone else.  Any ideas what's wrong or how I can debug it?
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
roarteam

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
roarteam

ASKER
Thanks CodeCruiser.  What I did was use the filter property instead:
 
Me.CustomerTBLBindingSource.Filter = "CustomerID = " & idNum

Open in new window

Works like a charm!
Your help has saved me hundreds of hours of internet surfing.
fblack61