sql - How to retrieve scalar value from stored procedure (ADO.NET) -
Text after "
In the archived process, I just select a statement from sometable , select the select count (*) , Then from the client side (I am implementing the stored procedure using C # ADO .net SqlCommand), how do I get the
count (*)
value? I am using SQL Server 2008.
I am confused because count (*)
thanks.
The return value of the stored procedure is not used as a parameter Advance, George
Or you suggested using Andrew as ExecuteScalar - or you have to change your code a little bit:
create process dbo.CountRowsInTable (@RowCount INT output) Select someTable end
and resume @RowCount = COUNT (*) Use this ADO.NET call to get the value:
(SqlCommand cmdGetCount = Using new SqlCommand ("dbo.CountRowsInTable", SqlConnection)) {cmdGetCount.CommandType = CommandType.StoredProcedure; CmdGetCount.Parameters.Add ("@RowCount", SqlDbType.Int). Direction = Parameter Direction.optput; SqlConnection.Open (); CmdGetCount.ExecuteNonQuery (); Int rowCount = Convert.ToInt32 (cmdGetCount.Parameters ["@owcount"]. Value); SqlConnection.Close (); }
Mark
PS: But in this concrete example, I just seem to be simple with implementing the ExecuteScalar
and simple to understand Easy to do This method may work well, if you need to return more than a single value (like many tables or more matters than these matters).
Comments
Post a Comment