VbMan wrote:
Ok,
I am racking my brain here and I have seen examplein C# but can not seem to translate it into Vb.Net. I need to extract a single value from a table in the db and I want to do it withou have to create a stored procedure everytime I need to do this. Can you give me some example code?
I am using .Net 1.1 and VB syntax.
Feeling like a newbie here and everthing I have tried fails. I am reading mounds of help documentation and forum postings just to get a simplistic funciton done.
You mean, retrieving a scalar value? It would really help if you could explain what you're using: selfservicing or adapter. Also, if you have a C# example, please post that. The manual contains VB.NET examples for EVERY C# example.
In Selfservicing you should use a GetScalar call on a collection, e.g.:
Selfservicing:
Dim orderDetails As New OrderDetailsCollection()
Dim productPriceExpression As IExpression = New Expression( _
OrderDetailsFields.Quantity, ExOp.Mul, OrderDetailsFields.UnitPrice))
Dim filter As IPredicate = New FieldCompareValuePredicate(OrderDetailsFields.OrderId, ComparisonOperator.Equal, 10254)
Dim orderPrice As Decimal = CDec(orderDetails.GetScalar(OrderDetailsFieldIndex.OrderId, _
productPriceExpression, AggregateFunction.Sum, filter))
Adapter:
Dim adapter As DataAccessAdapter = New DataAccessAdapter()
Dim productPriceExpression As IExpression = New Expression( _
OrderDetailsFields.Quantity, ExOp.Mul, OrderDetailsFields.UnitPrice)
Dim filter As IPredicate = New FieldCompareValuePredicate(OrderDetailsFields.OrderId, Nothing, ComparisonOperator.Equal, 10254)
Dim orderPrice As Decimal = CDec(adapter.GetScalar(OrderDetailsFields.OrderId, _
productPriceExpression, AggregateFunction.Sum, filter))
PS. While I am asking.. how about searching for any enitity without using the primary key?
Use a filter on a collection fetch. So use a predicate for the filter which should be the filter for the entity to find, and then fetch a collection with that filter.