简体   繁体   中英

Call update stored procedure with parameter list using Enterprise library 5.0?

I have the following stored procedure "ResponseTracking_Put_Request" with 15 parameters. Is it possible to pass a parameter list for ExecuteNonQuery command?

Instead of repeating ".AddInParamter" 15 times :

SqlDatabase db = new SqlDatabase(_connectionString);
DbCommand dbc = db.GetStoredProcCommand("ResponseTracking_Put_Request");
db.AddInParameter(dbc, "@requestId", DbType.Int32, requestId);
...
...
db.AddInParameter(dbc, "@description", DbType.String, description);
db.ExecuteNonQuery(dbc);

There is an ExecuteNonQuery overload that takes a stored procedure name and an array of objects. The objects will be used as parameters to the stored procedure.

SqlDatabase db = new SqlDatabase(_connectionString);
db.ExecuteNonQuery("ResponseTracking_Put_Request", requestId, description);

Or alternately:

List<object> parameters = new List<object>() { "123", "234", 99 }; 
db.ExecuteNonQuery("ResponseTracking_Put_Request", parameters.ToArray());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM