I’ve started using Enterprise Library and have the following questions:
1)How do I add output parameter to this query and how do I get it back:
public int InsertDoc(HDocument document)
{
Database db = DatabaseFactory.CreateDatabase();
int result;
var reader = db.ExecuteNonQuery("sp_InsertDocument",
document.AddedDate,document.AddedBy, document.Title))
.
.
.
}
The db.AddOutParameter requires paremetrers that I don’t have like DbCommand.
2)I have a few methods that work with database (I transfer from ADO.net) stored procedures,
do I have to declare : Database db = DatabaseFactory.CreateDatabase(); in each one of them or I can reuse it?
1) – You can make a DbCommand thusly:
and retrieve the output parameter after execution with:
Here’s a good example of using EntLib to execute a sproc with output params:
http://www.devx.com/dotnet/Article/30910/0/page/4
2) – You can use DatabaseFactory.CreateDatabase() in each method, that’s fine. EntLib will manage the connections as necessary.
As an aside, if you’re only using the db variable once in a method, then you could simplify your code slightly by using an inline temp instead of declaring a variable, i.e.: