
页面上输入用户名(user)和密码(pass),根据输入去(logoin)中检索:select
count(*)
from
logoin
where
admin=user
and
pwd=pass
判断count(*)>0,正确,否则不正确
,还有什么不明白的?
aspx 里面加2个textbox 一个button.cs文件里面代码 我的服务器是.
protected void Button1_Click(object sender, EventArgs e)
{
string connString = Convert.ToString(ConfigurationManager.ConnectionStrings["sqlconn"])
SqlConnection conn = new SqlConnection(connString)//创建数据库链接
conn.Open()
string strsql = "select * from stuent where StuName='" + TextBox1.Text + "'and Stupassword='" + TextBox2.Text + "'"
SqlCommand cmd = new SqlCommand(strsql, conn)
SqlDataReader dr = cmd.ExecuteReader()
if (dr.Read())
{
Session["StuName"] = dr["StuName"]
Session["Stupassword"] = dr["Stupassword"]
if (TextBox1.Text == Session["StuName"].ToString() &&TextBox2.Text == Session["Stupassword"].ToString())
{
Response.Redirect("Default2.aspx")
}
}
else
{
Label1.Text = "登陆失败,请检测输入!"
}
}
web.config
<add name="sqlconn" connectionString="Data Source=.Integrated Security=SSPIInitial Catalog=xuesheng" providerName="System.Data.SqlClient"/>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)