📄 index.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
this.Label1.Text = "欢迎您!" + Session["username"];
}
else
{
this.Label1.Visible = false;
this.LinkButton3.Visible = false;
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("App_Data\\news.mdb");
OleDbConnection conn = new OleDbConnection(strconn);
string Username = "";
string Pwd = "";
Username = TextBox2.Text.Trim();
Pwd = TextBox3.Text.Trim();
string Sql;
Sql = "select count(*) from userinfo where username='" + Username + "' and pwd='" + Pwd + "'";
OleDbCommand cmd = new OleDbCommand(Sql, conn);
conn.Open();
int ret = (int)cmd.ExecuteScalar();
conn.Close();
if (ret <= 0)
{
Response.Write("<script> alert(\"登录失败!用户名或密码错误!\")</script>");
}
else
{
Session["username"] = Username;
Response.Redirect("index.aspx");
}
}
}
protected void LinkButton3_Click1(object sender, EventArgs e)
{
Session["username"] = null;
Response.Redirect("index.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -