Is this possible or the right way to go about this (if you're not using a stored proc):
conn.CommandText = "set @T开发者_运维百科otalPts = select SUM (pts) from cars where completedDate is not null and customerID = @customerID";
                conn.AddParam("@customerID", customerID);
                conn.AddOutputParam("@TotalPts", SqlDbType.Int);
                return (int)conn.OutputParamValue;
I want to get back the sum so I can return it in my C# method. I'm not sure how to set the output param in the string.
You can instead use ExecuteScalar method as following.
conn.CommandText = select SUM (pts) 
                    from cars 
                    where completedDate is not null 
                           and customerID = @customerID";
obj count=cmd.ExecuteScaler();
Convert that count to Integer using Convert.ToInt32 function.
Use ExecuteScalar along with "select SUM (pts) from cars where completedDate is not null and customerID = @customerID".
It will give u what's in the first row / column, which is what u want.
"I'm not sure how to set the output param in the string."
select @TotalPts = SUM(pts) from ...
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论