ASP页面传递问题
时间:2011-09-02
来源:互联网
如何实现通过获取登陆界面的管理员的ID ,来绑定GridView控件,显示这个ID的管理员处理的信息
登陆界面的代码:
protected void Button1_Click(object sender, EventArgs e)
{
//获取输入的验证码
string code = txtCode.Text;
//判断用户输入的验证码是否正确
if (Request.Cookies["CheckCode"].Value == code)
{
//创建SQL Server 2000数据库连接
SqlConnection con = new SqlConnection("Server=(local);database=gwbn;uid=sa;pwd=;");
//打开数据库
con.Open();
//使用Md5加密
string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5");
string sqlSel = "select count(*) from gwbn_user where loginname=@username and password=@password";
SqlCommand com = new SqlCommand(sqlSel, con);
//使用Parameters的Add方法添加参数类型
com.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar, 50));
//设置Parameters的参数值
com.Parameters["username"].Value = txtUserName.Text;
com.Parameters.Add(new SqlParameter("password", SqlDbType.VarChar, 50));
com.Parameters["password"].Value = txtPassword.Text;
//判断ExecuteScalar方法返回的参数是否大于0,大于则表示登陆成功并给出提示
if (Convert.ToInt32(com.ExecuteScalar()) > 0)
{
Response.Redirect("Default.aspx");
//清空文本框
txtCode.Text = txtUserName.Text = "";
}
else
{
Response.Write("<script>alert('用户名或者密码错误')</script>");
}
}
else
{
Response.Write("<script>alert('验证码输入错误')</script>");
}
}
登陆界面的代码:
protected void Button1_Click(object sender, EventArgs e)
{
//获取输入的验证码
string code = txtCode.Text;
//判断用户输入的验证码是否正确
if (Request.Cookies["CheckCode"].Value == code)
{
//创建SQL Server 2000数据库连接
SqlConnection con = new SqlConnection("Server=(local);database=gwbn;uid=sa;pwd=;");
//打开数据库
con.Open();
//使用Md5加密
string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5");
string sqlSel = "select count(*) from gwbn_user where loginname=@username and password=@password";
SqlCommand com = new SqlCommand(sqlSel, con);
//使用Parameters的Add方法添加参数类型
com.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar, 50));
//设置Parameters的参数值
com.Parameters["username"].Value = txtUserName.Text;
com.Parameters.Add(new SqlParameter("password", SqlDbType.VarChar, 50));
com.Parameters["password"].Value = txtPassword.Text;
//判断ExecuteScalar方法返回的参数是否大于0,大于则表示登陆成功并给出提示
if (Convert.ToInt32(com.ExecuteScalar()) > 0)
{
Response.Redirect("Default.aspx");
//清空文本框
txtCode.Text = txtUserName.Text = "";
}
else
{
Response.Write("<script>alert('用户名或者密码错误')</script>");
}
}
else
{
Response.Write("<script>alert('验证码输入错误')</script>");
}
}
作者: jin864643722 发布时间: 2011-09-02
没人吗
作者: jin864643722 发布时间: 2011-09-02
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28