VS2008中,用户名密码都存在数据库里,怎样才能让登陆界面输入进去的内容和数据库相匹配呢?
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSys...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class xs_xs_login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Login_Click(object sender, EventArgs e)
{
SqlConnection Con = new SqlConnection();
Con.ConnectionString = "server=.\\vs2008;database=学生管理;user id=sa;password=sa";
SqlCommand Com = new SqlCommand();
Com.Connection = Con;
Com.CommandText = "select*from 学生档案 where 用户名='" + this.TextBox1 + "' and 密码='" + this.TextBox2 + "'";
SqlDataAdapter Da = new SqlDataAdapter();
Da.SelectCommand = Com;
DataSet Ds = new DataSet();
try
{
if (Ds.Tables[0].Rows.Count == 0)
{
this.Labinfo.Text = "用户名或密码错误,请重试!";
this.txt_User_Name.Focus();
}
else
{
this.Labinfo.Text = "用户" + this.txt_User_Name + "恭喜您登录成功!";
Session["UserName"] = this.txt_User_Name.Text;
Response.Redirect("学生档案");
}
}
catch (Exception)
{
this.Labinfo.Text = "没有得到任何数据,请重试";
}
}
protected void btn_Rgister_Clik(object sender, EventArgs e)
{
Response.Redirect("Reg.aspx");
}
} 展开
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class xs_xs_login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Login_Click(object sender, EventArgs e)
{
SqlConnection Con = new SqlConnection();
Con.ConnectionString = "server=.\\vs2008;database=学生管理;user id=sa;password=sa";
SqlCommand Com = new SqlCommand();
Com.Connection = Con;
Com.CommandText = "select*from 学生档案 where 用户名='" + this.TextBox1 + "' and 密码='" + this.TextBox2 + "'";
SqlDataAdapter Da = new SqlDataAdapter();
Da.SelectCommand = Com;
DataSet Ds = new DataSet();
try
{
if (Ds.Tables[0].Rows.Count == 0)
{
this.Labinfo.Text = "用户名或密码错误,请重试!";
this.txt_User_Name.Focus();
}
else
{
this.Labinfo.Text = "用户" + this.txt_User_Name + "恭喜您登录成功!";
Session["UserName"] = this.txt_User_Name.Text;
Response.Redirect("学生档案");
}
}
catch (Exception)
{
this.Labinfo.Text = "没有得到任何数据,请重试";
}
}
protected void btn_Rgister_Clik(object sender, EventArgs e)
{
Response.Redirect("Reg.aspx");
}
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
展开全部
string pwd= String.Format("select 密码 from 学生档案 where 用户名= {0}",TextBox1.text)
if (pwd == TextBox2.Text(密码))
{
执行登录;
}
if (pwd == TextBox2.Text(密码))
{
执行登录;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询