存储过程示例:
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息    ALTER PROCEDURE dbo.GetSumValue
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息    (
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息        
@IX int,
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息        
@IY int,
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息        
@IZ int
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息    )
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息    
AS
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息        
Return (@IX + @IY + @IZ);
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息

C#代码示例:
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息        Database db = DatabaseFactory.CreateDatabase("CS_QuickStarts"); // 创建一个 Database 对象
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息
        DbCommand cmd = db.GetStoredProcCommand("GetSumValue"); // 创建一个 DbCommand 对象
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息
        db.DiscoverParameters(cmd); // 显示参数信息
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息
        DbParameterCollection paras = cmd.Parameters; // 获取参数集合前一定要先调用 DiscoverParameters 方法
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息

Enterprise Library 2.0系列:获取存储过程的参数集的相关信息        
foreach (DbParameter para in paras)

运行结果:


参考文档:SHY520的《Enterprise Library 2.0 -- Data Access Application Block (补充) 》

SHY520的这篇日志是讲述存储过程参数调用方便的一种方法,写得很不错,我也学到了很多知识。

不过,我在查看《Enterprise Library January 2006 文档》的时候,发现 Database 中有一个现成的方法可以直接使用:
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息public virtual int ExecuteNonQuery (
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息    
string storedProcedureName,
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息    
params Object[] parameterValues
Enterprise Library 2.0系列:获取存储过程的参数集的相关信息)

稍后,我会继续测试这个方法的。

相关文章:

  • 2021-06-03
  • 2022-01-23
  • 2021-10-19
  • 2021-11-12
  • 2021-11-02
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2021-12-18
  • 2021-07-07
相关资源
相似解决方案