How to return a value from a query in code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.InvoiceInvNumColumn, 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. :)
 
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
 
Back
Top