Feb 16, 2007 at 5:29 PM
Edited Feb 16, 2007 at 5:30 PM
I'm using SQL Server 2005. I have Simple Stored Procedure that returns Table Records and RowCount as output parameter:
@RecordCount bigint OUTPUT
-- get record count
SELECT @RecordCount = (SELECT COUNT(ProductId) FROM
-- get table
SELECT * FROM StoreProducts
I'm using DAAB to get data from the procedure, but Output parameter returns nothing.
The only time it returns a result if I don't use second Sql Statement in procedure that actually returns table. Am I doing something wrong? Any ideas? Thanks !
Dim db As Database = DatabaseFactory.CreateDatabase()
Dim proc As String = "GetListByPage"
Dim cmd As DbCommand = db.GetStoredProcCommand(proc)
db.AddOutParameter(cmd, "@RecordCount", DbType.Int64, 0)
Dim dataReader As IDataReader = db.ExecuteReader(cmd)
Dim o As Object = db.GetParameterValue(cmd, "@RecordCount")
Feb 16, 2007 at 7:37 PM
Edited Feb 16, 2007 at 7:38 PM
It has to do with the fact that output parameters are not available until after the DataReader has been closed in ADO.NET.
Hence if you change your code to something like this it will work:
using (IDataReader dataReader = db.ExecuteReader(cmd))
// Do Something...
Int64 recordCount = (Int64)db.GetParameterValue(cmd, "@RecordCount");
Microsoft MVP C#