您的位置:首页 > 编程语言 > ASP

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

2008-05-24 13:11 447 查看

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();//断开连接


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐