• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Asp .net 调用带参数的存储过程

asp 搞代码 4年前 (2022-01-03) 22次浏览 已收录 0个评论

本文主要介绍了Asp .net 调用带参数的存储过程的相关知识。具有很好的参考价值。下面跟着小编一起来看下吧

1.后台调用带参数的存储过程详解

例:

注明:@AnalysisDate,@Process_PTR为存储过程参数

         IDataParameter[] iDataDi = new SqlParameter[2]; iDataDi[0] = new SqlParameter("@AnalysisDate", showDate); iDataDi[1] = new SqlParameter("@Process_PTR", ID); //获取检测项所选日期的不同时间 dtDifferTime = SqlHelper.RunProceduresByParameter("pro_Ge<strong style="color:transparent">来源gaodaima#com搞(代@码网</strong>tDifferenceTimeInfos", iDataDi);             //SqlHelper中的 RunProceduresByParameter(string storedProcName, IDataParameter[] parameters)方法:    /// <summary> /// 执行带参数的存储过程,返回DataSet类型 /// </summary> ///  ///  ///  public static DataSet RunProceduresByParameter(string storedProcName, IDataParameter[] parameters) { using (SqlConnection connection = new SqlConnection(connectionString)) { DataSet dataSet = new DataSet(); connection.Open(); SqlDataAdapter sqlDA = new SqlDataAdapter(); sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters); sqlDA.Fill(dataSet); connection.Close(); connection.Dispose(); return dataSet; } }    /// <summary> /// 构建 SqlCommand 对象(用来返回一个结果集,而不是一个整数值) /// </summary> /// 数据库连接 /// 存储过程名 /// 存储过程参数 /// SqlCommand private static SqlCommand BuildQueryCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters) { SqlCommand command = new SqlCommand(storedProcName, connection); command.CommandType = CommandType.StoredProcedure; foreach (SqlParameter parameter in parameters) { command.Parameters.Add(parameter); } return command; } 

2.存储过程创建语句

 USE [RedBSys_DB] GO /****** Object: StoredProcedure [dbo].[pro_GetDifferenceTimeInfos]  Script Date: 2017-03-22 16:34:13 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --获取检测项当天日期不同时间 CREATE proc [dbo].[pro_GetDifferenceTimeInfos] @AnalysisDate varchar(50), @Process_PTR int AS select distinct(AnalysisDate) from Assay_BillMain where CONVERT(varchar(100),AnalysisDate, 23)=@AnalysisDate and Process_PTR=@Process_PTR order by AnalysisDate ASC GO 

 

以上就是Asp .net 调用带参数的存储过程的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Asp .net 调用带参数的存储过程
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址