Asp .net 调用带参数的存储过程
程序员文章站
2023-11-29 21:05:04
1.后台调用带参数的存储过程详解
例:
注明:@analysisdate,@process_ptr为存储过程参数
idataparameter...
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)方法: /// <summary> /// 执行带参数的存储过程,返回dataset类型 /// </summary> /// <param name="storedprocname"></param> /// <param name="parameters"></param> /// <returns></returns> 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> /// <param name="connection">数据库连接</param> /// <param name="storedprocname">存储过程名</param> /// <param name="parameters">存储过程参数</param> /// <returns>sqlcommand</returns> 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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!