当前位置: 代码迷 >> SQL >> 存储过程解决方案
  详细解决方案

存储过程解决方案

热度:50   发布时间:2016-05-05 12:36:33.0
存储过程
存储过程:
ALTER proc User_Login_1
@UserID nchar(10),
@Password char(20),
@Return int=0 output
as
declare @flag int
select @flag=count(*) from [table] 
where @UserID=name and @Password=password
if @flag>0
begin
   select @Return=1   
end 

连接数据库:
SqlConnection con = dbobj.GetConnection();             
                    SqlCommand com = new SqlCommand();
                    com.Connection = con;
                    con.Open();
                    com.CommandType = CommandType.StoredProcedure;
                    com.CommandText = "User_Login_1";
                    com.Parameters.Add("@UserID", SqlDbType.NChar, 10).Value = user_text.Text.Trim();
                    com.Parameters.Add("@Password", SqlDbType.Char, 20).Value = password.Text.Trim();
                    com.Parameters.Add("@Return", SqlDbType.Int).Direction =ParameterDirection.Output;                                                                        
                    com.ExecuteNonQuery();
                    int i =Convert.ToInt32(com.Parameters["@Return"].Value); 
                    if (i>0)
                    {
                        Response.Write("<script language=javascript>alert('登陆成功');</script>");
                    }
                    else
                    {
                        Response.Write("<script language=javascript>alert('登陆不成功');</script>");
                    }
  相关解决方案