📄 reg.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 reg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
this.TextBox1.Text = "";
this.TextBox2.Text = "";
this.TextBox3.Text = "";
}
protected void Button2_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 = TextBox1.Text.Trim();
string sql = "select count(*) from userinfo where username='" + userName + "'";
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
int n = (int)cmd.ExecuteScalar();
if (n > 0)
{
Response.Write("<script> alert(\"该用户名已经存在! \") </script>");
return;
}
string Pwd = this.TextBox2.Text.Trim();
string Emai = this.TextBox3.Text.Trim();
string time = DateTime.Now.ToString();
string SqlAdd = "INSERT INTO userinfo(username,pwd,E_mail,addedtime) values('" + userName + "','" + Pwd + "','" + Emai + "','"+time+"')";
OleDbCommand MyCmd = new OleDbCommand(SqlAdd, conn);
MyCmd.ExecuteNonQuery();
conn.Close();
Session["username"] = userName;
Response.Write("<script> alert(\"恭喜您!注册成功!\") </script>");
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -