调用sqlserver中的存储过程
1、存储过程名
string strSQL = "usp_GetUnReturnPassports";
2、创建数据库对象 database
Database db = DatabaseFactory.CreateDatabase(ConfigHelper.CurrentConfig.LocalDBName);
3、创建数据库命令对象 DbCommand
DbCommand command = db.GetStoredProcCommand(strSQL);
4、添加参数
db.AddInParameter(command, "unitCode", DbType.String, unitCode.Substring(0, 3));
db.AddInParameter(command, "startDate", DbType.DateTime, startDate);
db.AddInParameter(command, "endDate", DbType.DateTime, endDate);
5、执行命令
DataSet ds = db.ExecuteDataSet(command);
6、读取结果
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
PassportBR one = new PassportBR();
one.Id = int.Parse(ds.Tables[0].Rows[i][0].ToString());
。。。。
}
额外知识点补充:
1、上面存储过程的写法
USE [cnpc]
GO
/****** Object: StoredProcedure [dbo].[usp_GetUnReturnPassports] Script Date: 05/23/2018 09:26:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: zhengwei 18963948278
-- Create date: 2016-12-28
-- Description: 获取应归还证照
-- =============================================
ALTER PROCEDURE [dbo].[usp_GetUnReturnPassports]
(
@unitCode nvarchar(6),
@startDate datetime,
@endDate datetime
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON; select b.Id,b.PassportNumber,b.Name,b.Xmbm,b.processedUnit,b.BorrowDate,b.ReceiverName,b.ReceiverTel,b.CashPledge,
b.MustReturnDate,b.ReturnDate,b.Depositary,b.RWPJLetterNumber,b.GroupName,b.BProcessedBy,b.RProcessedBy
from [PassportBR] b
left join hzhk k on b.passportNumber=k.hzhhm
left join ryk on ryk.xmbm=b.xmbm
where k.IsSetDeleted=0 and k.jchqk='Y' and k.xhrq is null and k.zhxrq is null and k.jzhrq>GETDATE()
--未标记删除的,借出状态的,未销毁的,未注销的,有效期内的
and b.RprocessedBy is null and b.MustReturnDate>'2016-8-1'
--未归还的,应归还日期是2016-8-1之后的
and (b.processedUnit=@unitCode or ryk.gzdw=@unitCode) and b.MustReturnDate between @startDate and @endDate
--护照保管单位+工作单位
END
调用sqlserver中的存储过程的更多相关文章
- C#调用SQL中的存储过程中有output参数,存储过程执行过程中返回信息
C#调用SQL中的存储过程中有output参数,类型是字符型的时候一定要指定参数的长度.不然获取到的结果总是只有第一字符.本人就是由于这个原因,折腾了很久.在此记录一下,供大家以后参考! 例如: ...
- java中调用数据库中的存储过程和函数
public static void main(String[] args) { Connection conn =getConnection(url,user, pwd); ...
- Mybatis调用Oracle中的存储过程和function
一.Mybatis调用存储过程 1 在数据库中创建以下的存储过程create or replace procedure pro_hello(p_user_name in varchar2,p_resu ...
- sqlserver中的存储过程 函数 事物 索引及视图
存储过程和函数具体的区别: 核心提示:本质上没区别.只是函数有限制只能返回一个标量,而存储过程可以返回多个.并且函数是可以 ...
- java调用Oracle中的存储过程与存储函数
1 //调用存储过程 2 public static void testPro(){ 3 String driver = "oracle.jdbc.OracleDriver"; 4 ...
- SQLServer中系统存储过程sp_spaceused
sp_spaceused 执行sp_spaceused存储过程的时候可以不用带参数,直接执行,或者exec sp_spaceused都可以,返回两个结果集: 列名 数据类型 描述 database_n ...
- SQLServer 中的存储过程中判断临时表是否存在,存在则删除临时表
IF OBJECT_ID('TEMPDB..#BCROSSREFERENCE ') IS NOT NULL DROP TABLE #BCROSSREFERENCE IF OBJECT_ID('TEMP ...
- sqlserver中查询存储过程中的字符串
select name from sysobjects o, syscomments s where o.id = s.id and text like '%querytext%' and o.xty ...
- 创建并在项目中调用SQLSERVER存储过程的简单示例
使用SQLSERVER存储过程可以很大的提高程序运行速度,简化编程维护难度,现已得到广泛应用.创建存储过程 和数据表一样,在使用之前需要创建存储过程,它的简明语法是: 引用: Create PROC ...
随机推荐
- raiden_graph
使用mermaid描述 raiden 通道 AB,正常状态 graph LR A-- 60,100,S_100 ---B 通道 AB closed graph LR A((A)) -. 60,100 ...
- could not read data from '/Users/lelight/Desktop/ViewControllerLife/ViewControllerLife/Info.plist': The file “Info.plist” couldn’t be opened because there is no such file.
1.Info.plist放置至新文件夹下,路径被修改了,报错. could not read data from '/Users/lelight/Desktop/ViewControllerLife/ ...
- 「BZOJ 1924」「SDOI 2010」所驼门王的宝藏「Tarjan」
题意 一个\(r\times c\)的棋盘,棋盘上有\(n\)个标记点,每个点有三种类型,类型\(1\)可以传送到本行任意标记点,类型\(2\)可以传送到本列任意标记点,类型\(3\)可以传送到周围八 ...
- 解决Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker fro问题
项目中碰到一个问题,就是将一个map转换成json格式的时候出现错误,最后排查将延迟加载关闭后成功转换,因为数据量较大,于是重新创建了一个对象进行接收. 解决办法是在配置文件中进行配置 虽然解决了这个 ...
- 如何下载网页上的视频 并且 flv 格式转化成 MP4
链接:http://www.jb51.net/softjc/222135.html https://jingyan.baidu.com/article/25648fc162f2899190fd0042 ...
- linux操作之文本编辑器
1.文本编辑器的作用 编辑和修改系统中的那些以文本形式存在的文件(特别是各种配置文件),也可以用于 编写程序代码 2.linux下的常见编辑器 nano.Emacs.gedit.vim等 3.vim三 ...
- 关于pip无法安装scrapy的问题
安装scrapy时如果出现下列问题: building ' twisted. test. raiser' extension error: Microsoft Visual C++ 14.0 is r ...
- .NET Core 版本不支持的问题
分析一个.NET Core开源项目(Ocelot),打开后发现提示当前版本.NET Core 不支持. 错误信息如下: The current .NET SDK does not support ta ...
- iOS如何检测app从后台调回前台
当按Home键,将应用放在后台之后,然后再次调用回来的时候,回出发AppDelegate里面的一个方法,-(void)applicationWillEnterForeground. 当应用再次回到后台 ...
- (转)win7英文目录和中文目录,文件夹的别名
win7英文目录和中文目录,文件夹的别名 在使用win7的很多目录例如我的文档.我的音乐等目录,你会发现文件夹是中文名的,路径也是中文的.但这个不是真的路径.点击一下地址栏,就可以看到真实路径了. 这 ...