It seems to me there are more than a few on the Enterprise Library forums (
http://www.codeplex.com/entlib/Thread/List.aspx) about how to call a stored procedure using the Data Access Application Block (DAAB). And every once in a while the question of how to get a return value from a stored procedure surfaces.
Since it's in my nature to be a problem solver, I have pushed out a couple of templates to the MyGeneration template library that will generate the correct DAAB code for you, one for VB and one for C#. The templates handle the following situations:
- Load the business entity -or- return a DataSet
- Execute only
- Return a DataReader
- Return a RETURN_VALUE
The templates do not gaurantee perfect code for every scenario, but at least provide you with a great starting point so you don't have to code the whole thing from scratch. It will automatically detect parameters and their input/output status, a return value if you request it, and add the correct parameters to the procedure and method signature. Checking the Static (or Shared in VB) option will generate proper DAAB code, unchecking it will generate the correct calls for an EO business entity.
It's a great timesaver when you are reverse-engineering an application with existing stored procedures that you have to call (I have been using it to add EasyObjects to the TimeTracker project from www.asp.net). I also use it to generate quick code examples when people ask "How do I call this stored procedure?" on the EntLib forum. People are sometimes shocked at the answer, either they missed something simple in their code, or they can't believe how easy it is.
To me, this is yet another example of why you should be using code generation as a part of your development methodology. It gives you and your development staff (no matter how large) a consistent and repeatable process for creating data access code, while at the same time increasing productivity and reducing errors. And hey, as long as you're checking out code generation, maybe give EasyObjects a spin, too? ;-)
Next on my list is a template for usage with the ObjectDataSource in ASP.NET.
Invoke a stored procedure - C#
http://www.mygenerationsoftware.com/TemplateLibrary/Template/?id=523a2083-1ca5-4dc9-a0c8-769b452c71e0 Invoke a stored procedure - VB.NET
http://www.mygenerationsoftware.com/TemplateLibrary/Template/?id=13696b88-9b79-402b-87c7-f87f42a7cfbb