how to get output parameters using enterprise library 2.0

  • Thread starter Thread starter xisco
  • Start date Start date
X

xisco

hi,
how do I get output parameters from sql 2005 query using the entlib 2,0?
I noticed the dbcommandwrapper is not there anymore.

thanks
xisco
 
DBCommandWrapper has been deprecated. The parameter functions are off the
Database class now. Here's some code from the QuickStart.

public string GetProductDetails(int productID)
{
// Create the Database object, using the default database
service. The
// default database service is determined through configuration.
Database db = DatabaseFactory.CreateDatabase();

string sqlCommand = "GetProductDetails";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

// Add paramters
// Input parameters can specify the input value
db.AddInParameter(dbCommand, "ProductID", DbType.Int32,
productID);
// Output parameters specify the size of the return data
db.AddOutParameter(dbCommand, "ProductName", DbType.String, 50);
db.AddOutParameter(dbCommand, "UnitPrice", DbType.Currency, 8);

db.ExecuteNonQuery(dbCommand);

// Row of data is captured via output parameters
string results = string.Format(CultureInfo.CurrentCulture, "{0},
{1}, {2:C} ",
db.GetParameterValue(dbCommand,
"ProductID"),
db.GetParameterValue(dbCommand, "ProductName"),
db.GetParameterValue(dbCommand, "UnitPrice"));

return results;
}

HTH

___________________________
Triax
 
Great. thanks!


Triax said:
DBCommandWrapper has been deprecated. The parameter functions are off the
Database class now. Here's some code from the QuickStart.

public string GetProductDetails(int productID)
{
// Create the Database object, using the default database
service. The
// default database service is determined through
configuration.
Database db = DatabaseFactory.CreateDatabase();

string sqlCommand = "GetProductDetails";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

// Add paramters
// Input parameters can specify the input value
db.AddInParameter(dbCommand, "ProductID", DbType.Int32,
productID);
// Output parameters specify the size of the return data
db.AddOutParameter(dbCommand, "ProductName", DbType.String, 50);
db.AddOutParameter(dbCommand, "UnitPrice", DbType.Currency, 8);

db.ExecuteNonQuery(dbCommand);

// Row of data is captured via output parameters
string results = string.Format(CultureInfo.CurrentCulture,
"{0}, {1}, {2:C} ",
db.GetParameterValue(dbCommand,
"ProductID"),
db.GetParameterValue(dbCommand, "ProductName"),
db.GetParameterValue(dbCommand, "UnitPrice"));

return results;
}

HTH

___________________________
Triax
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top