getting output parameter value from DAAB without using DbCommand ? plz guide

Topics: Data Access Application Block
Jan 12, 2010 at 8:40 AM
Edited Jan 12, 2010 at 11:17 AM


thanks for your attention and time, I need your help plz on writing DAAB code.


I am new to using DAAB, I found two ways to using it:

1. Using IDataReader with DBCommand and Database (db) class like:

DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, “EmployeeID”, DbType.Int32, 1);
db.AddOutParameter(dbCommand, “NationalIDNumber”, DbType.String, 15);


2. Using IDataReader without using DBCommand but with using Database class.

Using 1st way we have to put parameters one by one but by using way 2 allow without declaring parameters like:

db.ExecuteNonQuery("p_individualaccount_personaldetails",parameter1, parameter2,parameter3);

Way 2 is good as it give flexibility not to declare parameters but I am not getting how to get output parameter from it ? Please guide me on that.



Jan 12, 2010 at 9:08 AM


This thread is somehow related . But I dont see a way that will enable you to retrieve a out parameter without declaring a DbCommand instance. Since that the DbCommand instance is a parameter when retrieving the out parameter from the Database class. From the method Database.GetParameterValue(...) See this:

            Database db = DatabaseFactory.CreateDatabase();
            DbCommand cmd = db.GetStoredProcCommand("INSERT_PROJECT");
            db.AddInParameter(cmd, "@ProjectName", DbType.String, "Dudz2");
            db.AddOutParameter(cmd, "@ProjectID", DbType.Int32, 0);

            int projectID = Convert.ToInt32((db.GetParameterValue(cmd, @"ProjectID")));


Here is a FAQ item regarding the out parameter:


Valiant Dudan
Global Technology and Solutions
Avanade, Inc. 


Jan 12, 2010 at 11:28 AM

Thanks for attention and sharing,

Actually I want to use IDataReader with Database Class without using DBCommand because it allow to pass parameters without declaring them and it save lines of code.

If it (way 2) do not returns a output parameter then how I can get surety that operation like add/ edit or delete has been completed or not successful or not ?

Previously what I was doing was add or delete a record from stored procedure and then return a output parameter to application as a flag to indicate operation

was successful or not.


plz guide me,




Jan 13, 2010 at 2:24 AM

Your question is actually confusing because you said you want to use an IDataReader but in the code sample you showed above, you didn't use any IDataReader object.  Am I missing something?

But basing on the code you posted above, there would be no way for you to retrieve the output parameter as those are available in the DbCommand object that is created inside the ExecuteNonQuery method and you have no access to it.

Unless you're catching the exception inside your stored procedures, you would know if the database operation succeeded if there were no exceptions thrown after the database call.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.