栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

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

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

 

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/55723.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号