SQL存储过程的调用及写法
调用函数:
public class SqlProcess
{
public int ReturnValue = ;
public DataSet ReturnSet = null;
public SqlDataAdapter adapter = null; public SqlProcess(String proc,String uid,String pwd,String data,String ip) {
uid = Regex.Replace(uid,@"[^\w]*","");
pwd = Regex.Replace(pwd,@"[^\w]*",""); SqlConnection conn = new SqlConnection(Config.DBConnString);
conn.Open();
SqlCommand sqlcmd = new SqlCommand(proc, conn);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add(new SqlParameter("uid", uid));
sqlcmd.Parameters.Add(new SqlParameter("pwd", pwd));
sqlcmd.Parameters.Add(new SqlParameter("data", data));
sqlcmd.Parameters.Add(new SqlParameter("IP", ip));
SqlParameter returnParm = new SqlParameter("return", SqlDbType.Int);
returnParm.Direction = ParameterDirection.ReturnValue;
sqlcmd.Parameters.Add(returnParm);
adapter = new SqlDataAdapter(sqlcmd);
ReturnSet = new DataSet();
adapter.Fill(ReturnSet);
conn.Close();
ReturnValue = Convert.ToInt32(returnParm.Value);
}
}
sql存储过程:
USE [ServiceDB]
GO
/****** Object: StoredProcedure [dbo].[CheckIFlightPrivate] Script Date: 06/02/2013 10:32:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO -- Batch submitted through debugger: SQLQuery15.sql|7|0|C:\Documents and Settings\Administrator\Local Settings\Temp\~vs1860.sql ALTER PROCEDURE [dbo].[CheckIFlightPrivate]
(
@userId varchar(32),
@pwdMD5 varchar(32),
@data varchar(1024),
@IP varchar(16)
--@result int output
)
AS
BEGIN
DECLARE @accountPwd varchar(32),
@returnValue int,
@ID bigint; IF @userId is NULL or @userId = ''
BEGIN
EXEC @returnValue = ErrCode 10001;
RETURN @returnValue;
END
IF @pwdMD5 is NULL or @pwdMD5 = ''
BEGIN
EXEC @returnValue = ErrCode 10002;
RETURN @returnValue;
END
--登录
SELECT Top 1 @ID=ID,@accountPwd=userPwd FROM TUserInfo WHERE UserID = @userId;
IF @@ROWCOUNT = 0
BEGIN
EXEC @returnValue = ErrCode 10003;
RETURN @returnValue;
END
--有用户 验证是否是用独立MD5 DECLARE
@userMD5 varchar(50),
@BeginDateTime datetime,
@EndDateTime datetime,
@PerDayTimes bigint,
@LastDayUseTimes bigint,
@PerMonthTimes bigint,
@LastMonthUseTimes bigint,
@PerYearTimes bigint,
@LastYearUseTimes bigint,
@TotalTimes bigint,
@TotalUseTimes bigint,
@AllowedClientIP varchar(50),
@LastDayUpdateTime datetime,
@LastMonthUpdateTime datetime,
@LastYearUpdateTime datetime; SELECT TOP 1
@userMD5 = UserMD5,
@BeginDateTime = BeginDateTime,
@EndDateTime = EndDateTime,
@PerDayTimes = PerDayTimes,
@LastDayUseTimes = LastDayUseTimes,
@PerMonthTimes = PerMonthTimes,
@LastMonthUseTimes = LastMonthUseTimes,
@PerYearTimes = PerYearTimes,
@LastYearUseTimes = LastYearUseTimes,
@TotalTimes = TotalTimes,
@TotalUseTimes = TotalUseTimes,
@LastDayUpdateTime = LastDayUpdateTime,
@LastMonthUpdateTime = LastMonthUpdateTime,
@LastYearUpdateTime = LastYearUpdateTime,
@AllowedClientIP = AllowedClientIP FROM TIFlightPrivate WHERE UserID=@ID;
--登录成功--验证功能 IF @@RowCount = 0
BEGIN
EXEC @returnValue = ErrCode 10010;
RETURN @returnValue;
END
ELSE
BEGIN
IF @userMD5 is NULL OR @userMD5 = ''
BEGIN
--用帐号的MD5;
IF @pwdMD5 <> @accountPwd
BEGIN
EXEC @returnValue = ErrCode 10004;
RETURN @returnValue;
END END
ELSE IF @pwdMD5 <> @userMD5
BEGIN
EXEC @returnValue = ErrCode 10006;
RETURN @returnValue;
END
END --验证 更新查询次数 -- 更新次数
if datediff(dd,@LastDayUpdateTime,getdate()) > 0
begin
set @LastDayUseTimes = 0;
set @LastDayUpdateTime = getdate();
end
if datediff(dd,dateadd(mm,1,@LastMonthUpdateTime),getdate()) > 0
begin
set @LastMonthUseTimes = 0;
set @LastMonthUpdateTime = getdate();
end
if datediff(dd,dateadd(yy,1,@LastYearUpdateTime),getdate()) > 0
begin
set @LastYearUseTimes = 0;
set @LastYearUpdateTime = getdate();
end IF @EndDateTime is not null and getdate() > @EndDateTime
begin
SELECT '该帐号已于'+convert(varchar,@EndDateTime,20)+'过期!' AS ErrInfo;
return 0;
end
else if @AllowedClientIP is not null and charindex(@IP,@AllowedClientIP) = 0
begin
SELECT '该帐号限制访问IP为:'+@AllowedClientIP AS ErrInfo;
return 0;
end
else if @PerDayTimes is not null and @PerDayTimes>0 and @LastDayUseTimes >= @PerDayTimes
begin
SELECT '该帐号已经超过当天查询次数:'+ convert(varchar,@perDayTimes) +'次' AS ErrInfo;
return 0;
end
else if @PerMonthTimes is not null and @PerMonthTimes>0 and @LastMonthUseTimes >= @PerMonthTimes
begin
SELECT '该帐号已经超过当月查询次数:'+ convert(varchar,@PerMonthTimes) +'次' AS ErrInfo;
return 0;
end
else if @PerYearTimes is not null and @PerYearTimes>0 and @LastYearUseTimes >= @PerYearTimes
begin
SELECT '该帐号已经超过当年查询次数:'+ convert(varchar,@PerYearTimes) +'次' AS ErrInfo;
return 0;
end
else if @TotalTimes is not null and @TotalTimes>0 and @TotalUseTimes >= @TotalTimes
begin
SELECT '该帐号已经超过总查询次数:'+ convert(varchar,@TotalTimes) + '次' AS ErrInfo;
return 0;
end
else
begin
update TIFlightPrivate set LastDayUseTimes=@LastDayUseTimes+1,
LastMonthUseTimes=@LastMonthUseTimes+1,
LastYearUseTimes=@LastYearUseTimes+1,
TotalUseTimes=@TotalUseTimes+1,
LastDayUpdateTime=@LastDayUpdateTime,
LastMonthUpdateTime=@LastMonthUpdateTime,
LastYearUpdateTime=@LastYearUpdateTime Where UserID=@ID;
--set @result = '该帐号有效日期至:'+ convert(varchar,@EndDateTime,120) + ',当天剩余次数,当月剩余次数,当年剩余次数,总剩余次数';
end --默认城市地方
return 1
END
SQL存储过程的调用及写法的更多相关文章
- SQL存储过程来调用webservice
如果用存储过程来调用webservice 那存储过程的功能感觉能做好多事情了? 别自欺欺人了.那些功能还是webservice来实现的... 完整的webservice代码:(也是默认的,新建.asm ...
- SQL 存储过程里调用另一个存储过程
由于创建了一个存储过程,并且要在另一个存储过程里调用这个存储过程所以在网上找了一下相关的代码,现在总结一下,防止以后还会用到 由于这次我写的存储过程只需要返回一个求和的结果,所以我使用了output ...
- SQL——存储过程实例 调用带参数的过程(成绩输出)
create or replace procedure test_score(input in number,output out char) is begin then begin output : ...
- SQL存储过程概念剖析
一.SQL存储过程的概念,优点及语法 定义:将常用的或很复杂的工作,预先用SQL语句写好并用一个指定的名称存储起来, 那么以后要叫数据库提供与已定义好的存储过程的功能相同的服务时,只需调用execut ...
- (转载)delphi 中如何调用sql 存储过程
delphi 中如何调用sql 存储过程 使用TADOStoredProc组件,可以,给你举个例子好了 with ADOStoredProc1 do begin Close; Parameters.C ...
- discuz 万能SQL查询调用语句写法
首先在最底层source\class\table写入底层安全调用文件例如:table_common_friendlink.php 代码: <?php /** * [Discuz!] (C)200 ...
- C# 连接Oracle,并调用存储过程(存在返回值),C# 调用sql存储过程
1.获取Oracle表格信息 public OracleHelpers(string ConnStr) { ConnectionString = ConnStr; conn = new OracleC ...
- sql 存储过程 in 的两种写法
最近又忘记存储过程 除了exec 动态写法的另外一种,这里记录一下,方便查找 写法1,动态语句 CREATE PROCEDURE sp_CountShiftWish @strids varchar ( ...
- 在 SQL Server 的存储过程中调用 Web 服务
介绍 一个老朋友计划开发一个应用,基于 .NET 和 Socket,但需要在存储过程中调用 Web 服务. 在这篇文章中我们将分享这个应用的经验,讲述如何在存储过程中调用 Web 服务,并传递参数. ...
随机推荐
- Nmap源码分析(脚本引擎)
Nmap提供了强大的脚本引擎(NSE),以支持通过Lua编程来扩展Nmap的功能.目前脚本库已经包含300多个常用的Lua脚本,辅助完成Nmap的主机发现.端口扫描.服务侦测.操作系统侦测四个基本功能 ...
- MyEclispe 2015 CI 15发布(附下载)
MyEclipse 2015 CI 15带来了一些程序上的改进,包括可外部部署的JavaScript调 试,改进了 REST Inspect 和 WebSphere 框架支持,新增服务器连接器,另外还 ...
- MapGuide Maestro 5.1发布了
MapGuide Maestro最为MapGuide开源版的authoring工具真是发展迅速,有些功能比Infrastructure Studio还给力,现在5.1版已经发布了.大家可以到http: ...
- LeakCanary中英文文档+使用例子
Android 开源界最伟(jian)大(zhi)高(kai)效(gua)的公司 Square 又向业界投下一颗重磅炸弹.推出了一个叫 LeakCanary 的玩意儿,可以通过简单粗暴的方式来让开发者 ...
- 操作系统开发系列—12.a.从Loader到内核 ●
Loader要做两项工作,我们先来做第一项,把内核加载到内存: 1.加载内核到内存. 2.跳入保护模式. 首先编译无内核时: nasm boot.asm -o boot.bin nasm loader ...
- 操作系统开发系列—4.LDT
一直以来,我们把所有的段描述符都放在GDT中,而不管它属于内核还是用户程序,为了有效地在任务之间实施隔离,处理器建议每个任务都应当具有自己的描述符表,称为局部描述符表LDT,并且把专属于自己的那些段放 ...
- 初学Spring有没有适合的书
初学者之前没有阅读java框架源码的习惯.没有阅读过源码,知道整体流程么?知道依赖注入的概念么?知道aop么?知道其中用到了哪些设计模式么?再说了,如果一上手就是源码?难道你没有注意到Spring的类 ...
- Android 常用数据适配器SimpleAdapter
在<Android 常用数据适配器ArrayAdapter>中介绍了ArrayAdapter数据适配器.但是存在一个缺陷,那就是条目的图标都固定相同,要显示每个条目的图标都不相同,那么使用 ...
- 运算符&,|,^
1.&按位“与”的计算是把两个数字分别写成二进制形式,然后按照每一位进行比较,&计算中,只要有一个是0就算成02.|运算转换成2进制进行比较,两个位只要有一个为1,那么结果就是1,否则 ...
- C++ virtual虚函数
#include<iostream> using namespace std; class Base{ public: void m() { cout << "it' ...