引用自:
Enterprise Library 2.0 -- Data Access Application Block 和 加密数据库连接字符串
http://www.cnblogs.com/adamoooo/articles/892618.html
取得存储过程的返回值、输出参数
带输出参数的:
try
{
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetStoredProcCommand("usp_xxx");
db.AddParameter(cmd, "@UserID", DbType.Int32, ParameterDirection.InputOutput, "", DataRowVersion.Current, dict.Get("UserID", 0));
db.AddInParameter(cmd, "@LoginName", DbType.String, dict["LoginName"]);
db.ExecuteNonQuery(cmd);
return DictionaryEx.Create("UserID", db.GetParameterValue(cmd, "@UserID"));
}
catch (Exception)
{
return null;
}
带返回值:
try
{
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetStoredProcCommand("usp_xxx");
db.AddInParameter(cmd, "@UserID", DbType.Int32, dict["UserID"]);
db.AddParameter(cmd, "@ret", DbType.Int32, ParameterDirection.ReturnValue, "", DataRowVersion.Default, null);
db.ExecuteNonQuery(cmd);
return cmd.Parameters["@ret"].Value;
}
catch (Exception)
{
return null;
}
查询返回结果集:
try
{
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetStoredProcCommand("usp_xxx");
db.AddInParameter(cmd, "@rowStart", DbType.Int32, dict.Get("rowStart", null));
db.AddInParameter(cmd, "@rowEnd", DbType.Int32, dict.Get("rowEnd", null));
return db.ExecuteDataSet(cmd);
}
catch (Exception)
{
return null;
}
posted on 2010-04-05 22:26
黄小二 阅读(422)
评论(0) 编辑 收藏 所属分类:
ASP.NET 、
C#