protected void Button1_Click(object sender, EventArgs e)
{
/* string m_sex;
if (radsex1.Checked == true)
m_sex = "男";
else
m_sex = "女";*/
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source= " + Server.MapPath("App_Data/hjw.mdb"));
string sql = "select * from 注册 where username='" + Username.Text + "'";
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.Connection.Open();
OleDbDataReader reader;
reader = cmd.ExecuteReader();
if (reader.Read() == true)
{
Response.Write("<script>alert('对不起!该用户已经存在!');</script>");
Username.Text = "";
Username.Focus();
return;
}
else
{
cmd.Connection.Close();
string addsql = "insert into 注册(username,pwd) values ('" + Username.Text + "','" + Password.Text + "')";
OleDbCommand cmd1 = new OleDbCommand(addsql, conn);
cmd1.Connection.Open();
cmd1.ExecuteNonQuery();
cmd1.Connection.Close();
Response.Write("<script>alert('恭喜你!注册成功!');</script>");
this.Response.Redirect("Default2.aspx");
}
“注册:沩你的表名里面有username 和 pwd , 数据库名沩hjw.mdb 含两个TextBox : Username 和 Password ; 一个button : button1;
自己修改哈。