您现在的位置是:网站首页> 编程资料编程资料
Asp .net 调用带参数的存储过程_实用技巧_
2023-05-24
483人已围观
简介 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_GetDifferenceTimeInfos", iDataDi); //SqlHelper中的 RunProceduresByParameter(string storedProcName, IDataParameter[] parameters)方法: /// /// 执行带参数的存储过程,返回DataSet类型 /// /// /// /// 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; } } /// /// 构建 SqlCommand 对象(用来返回一个结果集,而不是一个整数值) /// /// 数据库连接 /// 存储过程名 /// 存储过程参数 /// 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使用ajax实现分页局部刷新页面功能_实用技巧_
- 使用Topshelf组件构建简单的Windows服务_实用技巧_
- ASP.NET导出word实例_实用技巧_
- Visual Studio ASP.NET Core MVC入门教程第一篇_实用技巧_
- Visual Studio 2017中找回消失的“在浏览器中查看”命令_实用技巧_
- Opencv2.4.13与Visual Studio2013环境搭建配置教程_实用技巧_
- .NET中可空值类型【Nullable<T>】实现原理_实用技巧_
- asp.net利用母版制作页脚效果_实用技巧_
- Asp.Net服务器发送HTTP标头后无法设置内容类型的问题解决_实用技巧_
- 使用asp.net mvc,boostrap及knockout.js开发微信自定义菜单编辑工具(推荐)_实用技巧_
