DAAB 5: how to pass Parameter Array to ExecuteDataSet/ExecuteNonquery

Topics: Data Access Application Block
Jul 21, 2011 at 12:43 PM


I am using EntLib 5.0 and have the following two scenarios:

a) Passing Input Parameters to SP and returning it as DataSet - using ExecuteDataSet

b) Passing  Input Parameters to SP and returning output parameters - using ExecuteNonquery

This is what I have currently, but I would like to do the same using Parameter Discovery where DbType and Name need not be provided and I can pass array directly

command = db.GetStoredProcCommand("sp_TestProc");
foreach (DbParameter p in param)
        db.AddInParameter(command, p.ParameterName, p.DbType, p.Value.ToString());

returnSet = db.ExecuteDataSet(command);

Similarly how do I provide param array values to ExecuteNonQuery and expect a output paramter as well?




Jul 22, 2011 at 7:25 AM


You can use the ExecuteNonQuery of your DbCommand instead. Suppose you have a stored proc named "sp_MyStoredProc" which accepts a varchar and int and outputs an int.

        DbCommand command =  db.GetStoredProcCommand("sp_MyStoredProc","firstParameter", 2, null);         
Note that you should pass a null value to your output parameter.  For more details, kindly refer to the Parameter Discovery from MSDN.

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us