通过使用存储过程的 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();//断开连接
}
相关文章推荐
- ASP.NET jQuery 实例11 通过使用jQuery validation插件简单实现用户登录页面验证功能
- 编写asp.net登录界面时,在不会使用cookie的情况下,暂时解决方法.
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- [ASP.NET]更简单的方法:FormsAuthentication登录ReturnUrl使用绝对路径
- asp.net 通过ajax方式调用webmethod方法使用自定义类传参及获取返回参数
- 关于asp.net网站发布后,使用登录控件和注册控件时出现“数据库只读,无法进行数据更新”的解决方法
- 在ASP.NET MVC中使用Knockout实践02,组合View Model成员、Select绑定、通过构造器创建View Model,扩展View Model方法
- asp.net- ajax简单入门使用方法,通过一般处理程序ashx进行处理
- asp.net 使用JQuery 调用Ashx 后面直接写方法名,通过反射找到对应的方法
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- 一起谈.NET技术,在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- ASP.NET jQuery 食谱11 (通过使用jQuery validation插件简单实现用户登录页面验证功能)
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- asp.net(存储过程)使用三种方法存取数据库记录(20070510)
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- 如何在ASP.NET中使用验证通过的Windows Live ID用户登录网站
- [ASP.NET]更简单的方法:FormsAuthentication登录ReturnUrl使用绝对路径