通过使用存储过程的 Asp.net 登录方法

 

ConnectionClass objconn = new  ConnectionClass(); // 实例化一个连接类            
SqlConnection logConn  =  objconn.GetConnection();
            DataSet logDs 
=   new  DataSet(); // 实例化一个数据集
             try
            ...
{
                SqlCommand logCmd 
= logConn.CreateCommand();  //定义命令变量
                logCmd.CommandType = CommandType.StoredProcedure;//指定命令变量的类型
                logCmd.CommandText = "LoginProc";//指定命令变量的执行语句为存储过程名
                logCmd.Parameters.Add(new SqlParameter("@Id", txtId.Text.Trim().ToString()));//添加参数
                logCmd.Parameters.Add(new SqlParameter("@pwd", txtPassword.Text.Trim().GetHashCode().ToString()));//添加参数
//注意:参数名 和个数必须与存储过程的参数一样
                SqlDataAdapter logSda = new SqlDataAdapter(logCmd);//定义适配器
                logSda.Fill(logDs, "userinfo");//填充适配器
                if (logDs.Tables["userinfo"].Rows.Count > 0)
                ...
{
                    
string objui="";
                    objui
=txtId.Text.Trim().ToString();
                    Session.Add(
"wid",objui);//写入Session
                    
//Response.Write("<script language='JavaScript'>alert('用户名、密码 正确 !')</script>");
                    Response.Redirect("mainFrame/mainframe.htm" );     //转向页面               
                }

                
else
                ...
{
                    Response.Write(
"<script language='JavaScript'>alert('用户不存在 或 密码不正确 !')</script>");
                    
return;
                }

            }

            
catch  (Exception ex)
            ...
{
                Response.Write(
"<script language='JavaScript'>alert('登录失败 !')</script>");
                
return;
            }

            
finally
            ...
{
                logConn.Close();
//断开连接
            }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值