Home  >  Article  >  Database  >  存储过程、事务、触发器。

存储过程、事务、触发器。

WBOY
WBOYOriginal
2016-06-07 17:38:56952browse

一、调用带两个普通参数和一个输出参数的存储过程实现账号密码的验证。 存储过程为如下代码: create proc St_exam@adm varchar(50),@pwd varchar(50),@result int=1 outputasselect @result=COUNT(*) from Manage where Admin=@adm and Pwd=@pwdreturn @res

一、调用带两个普通参数和一个输出参数的存储过程实现账号密码的验证。

    存储过程为如下代码:

create proc St_exam @adm varchar(50), @pwd varchar(50), @result int=1 output as select @result=COUNT(*) from Manage where Admin=@adm and Pwd=@pwd return @result

ASP.NET代码为如下:

protected void Page_Load(object sender, EventArgs e) { St_Proc(,); } public void St_Proc(string Adm, string Pwd) { SqlConnection conn = ); conn.Open(); SqlCommand cmd = , conn); // "St_exam" 为存储过程名 cmd.CommandType = CommandType.StoredProcedure; //设置命令类型为存储过程 SqlParameter[] pa = { ,SqlDbType.VarChar), SqlParameter(,SqlDbType.VarChar), SqlParameter(,SqlDbType.Int)}; pa[0].Value = Adm; // 给参数赋值 pa[1].Value = Pwd; pa[2].Direction = ParameterDirection.Output; //设置输出参数的输出方向 相当于获取输出参数的值
cmd.Parameters.AddRange(pa); cmd.ExecuteNonQuery(); int result = int.Parse(cmd.Parameters[2].Value.ToString()); if (result==1) { Response.Write(); } else { Response.Write(); } }

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn