Print Page | Close Window

Finding an Entity by Primary Key in a Binding Source returns -1

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=135
Printed Date: 26-Jan-2026 at 8:36pm


Topic: Finding an Entity by Primary Key in a Binding Source returns -1
Posted By: Customer
Subject: Finding an Entity by Primary Key in a Binding Source returns -1
Date Posted: 12-Jul-2007 at 10:39am

At some point in my application I need to find the employee using the value of his primary key ( I have that value of primary key ).

I tried something like:

 

bindingSource1.Position=bindingSource1.Find(“IdEmployee”, valueOfPrimaryKeyIKnowIt);

 

but bindingSource1.Find(“IdEmployee”, valueOfPrimaryKeyIKnowIt) returns -1.

 

I know how to get the independent Employee using:

 

PrimaryKey pk = new PrimaryKey(typeof(Employee), valueOfPrimaryKeyIKnowIt);

Employee anEmployee = MainPm.Manager.GetEntity<Employee>(pk, QueryStrategy.Normal);

 

But I don’t need an independent object; I need to keep in bindingSource1 all Employees  but to be able to set current position to an Employee by his primary key.

 

Can you help me ?

 




Replies:
Posted By: IdeaBlade
Date Posted: 12-Jul-2007 at 10:43am
We found that in fact the BindingSource Find method will return a correct result if the data type of the second parameter exactly matches the data type of the property whose name is given in the first parameter.  In my testing, for example, I did a Find call on a BindingSource instance that was populated with OrderSummary entities from our IdeaBladeTutorial sample database.  I specified "Id" as the column name to search on and a particular value of Id to find.  I saw the same symptoms you did, namely that the call returned -1.  When I encapsulated my Id value to find in a Convert.ToInt64() call, remembering that the "Id" column is of type Int64, the find call returned the correct result.
 
Please try using the Find command, making sure that the data types of the column you are searching on and the value you are searching for match exactly. 



Print Page | Close Window