grabbing the value of a single field in a single table

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 18-May-2007 13:44:17   

version 1.0.2005.1 final (self-servicing) VS2005 asp.net 2.0


hiya,

I want to grab the value of a single field in a single table. It’s the opposite of the “entity.FetchUsingPK()” function.

I have 2 field values, which, when taken together, guarantee uniqueness: orderStatusID username

And I want to use them to return the value of the primaryKey in the table, ie orderId

So, the query would be

SELECT orderID FROM tblOrder WHERE orderStatusID = 99 AND username =”Jimmy”

I believe that I won’t need to use an entityCollection (because I only want a single, non-computed value)??

many thanks,

yogi

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-May-2007 15:18:57   

SELECT orderID FROM tblOrder WHERE orderStatusID = 99 AND username =”Jimmy”

Should like the following:

OrderCollection orders = new OrderCollection();
int orderId = (int)orders.GetScalar(OrderFieldIndex.OrderId, null, AggregateFunction.None /*or AggregateFunction.Max*/, 
    ((OrderFields.OrderStatusId == 99) && (OrderFields.UserName == "Jimmy")));

The OrderCollection is just used to call the GetScalar() method, it's not filled with data, the GetScalar() method only returns one value (with an object type, that's why we should cast it to whatever .NET type that we are fetching)