Re: How to return a value from a query in code



You have to instantiate a SqlCECommand on a connection, to execute the command with a given parameter. Since your query only returns one value, the .ExecuteScalar method of the SqlCeCommand would be the more appropriate.

Alberto Silva
MS Mobile Devices MVP
http://msmvps.com/AlbertoSilva

I already had set up a query set up but I didn't know how to get the
result
in code.
Here is what I had:
SELECT SUM(Amount) AS EXPR1
FROM LineItem
WHERE (InvNum = @number)
Here is what I tried in my code to run it but I obviously don't
understand
what it needs.
This is what it asks for before I type after the (
decimal?CalcItems(int,Number)
my code:
float amt = 0;
this.lineItemTableAdapter.CalcItems(fB7MobileDBDataSet.LineItem.Invoic
eInvNumColumn, amt);

I thought I was giving it the InvoiceNum column for the @number
parameter and the amt var to hold the result. I get the error no
overload method CalcItems takes two arguments. ??

Thanks Jon Stroh hope you can straighten me out. :)



.



Relevant Pages

  • Re: Selecting one record from SQL CE table
    ... How can I see how many records are in SqlCeDataReader? ... > Use SqlCeCommand object's ExecuteScalar method and you can retrieve a ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Selecting one record from SQL CE table
    ... Use SqlCeCommand object's ExecuteScalar method and you can retrieve a single ... IsDBNull method, which returns a boolean indicating record return status. ...
    (microsoft.public.dotnet.framework.compactframework)