C#中调用输入输出参数的存储过程
2008-08-27 22:15
393 查看
关于存储过程的介绍大家想必也不陌生了吧。大家可以参考《浅谈存储过程》一文,这里不做介绍。
今天要介绍的是在C#里如何调用带输入输出参数的存储过程。譬如实现简单的登陆功能,根据用户输入的用户名、用户密码及用户权限实现登陆。这里充当输入参数的有:用户名、用户密码、登陆权限。充当输出参数的就是在数据库里面根据输入参数的信息查询数据库中是否有记录。具体来说就是记录的行数。
数据库中的存储过程构建代码:
use Hotel --数据库名
2if exists(select * from sysobjects where name='proc_userinfo')--判断是否存在存储过程
3drop proc proc_userinfo --若存在删除此存储过程
4go
5--创建存储过程
6create proc proc_userinfo
7@username varchar(50),--输入参数
8@pwd varchar(50),--输入参数
9@grade varchar(20),--输入参数
10@count int output --输出参数output不能少
11--sql语句
12as
13select @count=count(*) from userinfo where username=@username and pwd=@pwd and @grade=grade
14go
15
16
17执行存储过程
18declare @n int
19exec proc_userinfo admin,123,管理员,@n output
20--output不能少
21print @n
22go
数据访问层代码
//调用存储过程执行类似于
2//select count(*) from userinfo where username=username and pwd=pwd and grade=grade
3//接受三个参数分别用来表示用户名、用户密码、用户权限
4public bool GetUserinfo(string username,string pwd,string grade)
5//用dataGradeView.DataSource dataGradeView的数据源创建一个DataTable 对象 需要强转成DataTable
2
3 DataTable dt=(DataTable )dataGradeView.DataSource;
4 //dataGradeView为具体的dataGradeView
5
6 dt.Rows.Clean(); //删除表中的行
7
8 dataGradeView.DataSource=dt;
9//再把dt绑定到dataGradeView上即可
10
今天要介绍的是在C#里如何调用带输入输出参数的存储过程。譬如实现简单的登陆功能,根据用户输入的用户名、用户密码及用户权限实现登陆。这里充当输入参数的有:用户名、用户密码、登陆权限。充当输出参数的就是在数据库里面根据输入参数的信息查询数据库中是否有记录。具体来说就是记录的行数。
数据库中的存储过程构建代码:
use Hotel --数据库名
2if exists(select * from sysobjects where name='proc_userinfo')--判断是否存在存储过程
3drop proc proc_userinfo --若存在删除此存储过程
4go
5--创建存储过程
6create proc proc_userinfo
7@username varchar(50),--输入参数
8@pwd varchar(50),--输入参数
9@grade varchar(20),--输入参数
10@count int output --输出参数output不能少
11--sql语句
12as
13select @count=count(*) from userinfo where username=@username and pwd=@pwd and @grade=grade
14go
15
16
17执行存储过程
18declare @n int
19exec proc_userinfo admin,123,管理员,@n output
20--output不能少
21print @n
22go
数据访问层代码
//调用存储过程执行类似于
2//select count(*) from userinfo where username=username and pwd=pwd and grade=grade
3//接受三个参数分别用来表示用户名、用户密码、用户权限
4public bool GetUserinfo(string username,string pwd,string grade)
5//用dataGradeView.DataSource dataGradeView的数据源创建一个DataTable 对象 需要强转成DataTable
2
3 DataTable dt=(DataTable )dataGradeView.DataSource;
4 //dataGradeView为具体的dataGradeView
5
6 dt.Rows.Clean(); //删除表中的行
7
8 dataGradeView.DataSource=dt;
9//再把dt绑定到dataGradeView上即可
10
相关文章推荐
- c#带输入输出参数调用存储过程
- C#中调用输入输出参数的存储过程
- 存储过程输出参数:C#中调用输入输出参数的存储过程
- C# 调用带输入输出参数的存储过程
- 关于C#中如何调用有输入参数和输出参数的存储过程
- C#调用存储过程详解(带返回值、参数输入输出等)
- [转]C#中调用SQL存储过程(带输入输出参数的例子)
- C#中调用SQL存储过程(带输入输出参数的例子)
- 存储过程有输出参数,在c#中用nhibernate调用存储过程时,如何才能获取到一个结果集和这个输出参数呢?
- C#中调用SQL存储过程(带输入输出参数的例子)
- C#中调用SQL存储过程(带输入输出参数的例子)
- C#调用带输入输出参数的存储过程
- C#里调用带输出参数的存储过程
- ASP.NET中调用存储过程带(输入/输出)参数和返回值
- C#调用存储过程 之返回值与输出参数
- C#里调用带输出参数的存储过程
- C#中调用SQL存储过程(带输入输出参数的例子)
- C#中调用存储过程:带输入输出参数
- c#调用存储过程输出参数
- c#调用带输出参数的存储过程