62,025
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings["SperConnectionString1"].ToString();
SqlConnection ConnSql = new SqlConnection(strConn);
ConnSql.Open();
string strSQL = "SELECT * FROM wyx_user WHERE wyx_name='" + TextBox1.Text + "'";
SqlCommand cmd = new SqlCommand(strSQL, ConnSql);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())//如果用户名存在
{
Response.Write("<script>alert('对不起,用户名已被注册,请换个名称,谢谢!')</script>");
}
else
{
string password = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5");
string strSQL1 = "INSERT INTO wyx_user (wyx_name,wyx_pass) VALUES ('" + TextBox1.Text + "','" + password + "')";
SqlCommand cmd1 = new SqlCommand(strSQL1, ConnSql);
cmd1.ExecuteNonQuery();
Response.Write("<script>alert('添加成功!')</script>");
}
dr.Close();
ConnSql.Close();
Response.Redirect("admin_admin.aspx");//返回管理页面
}
if (dr.Read())//如果用户名存在
{
Response.Write("<script>alert('对不起,用户名已被注册,请换个名称,谢谢!')</script>");
}
else
{
dr.Close();
string password = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5");
string strSQL1 = "INSERT INTO wyx_user (wyx_name,wyx_pass) VALUES ('" + TextBox1.Text + "','" + password + "')";
SqlCommand cmd1 = new SqlCommand(strSQL1, ConnSql);
cmd1.ExecuteNonQuery();
Response.Write("<script>alert('添加成功!')</script>");
}
if (dr.Read())//如果用户名存在
{
Response.Write("<script>alert('对不起,用户名已被注册,请换个名称,谢谢!')</script>");
}
else
{
string password = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5");
string strSQL1 = "INSERT INTO wyx_user (wyx_name,wyx_pass) VALUES ('" + TextBox1.Text + "','" + password + "')";
SqlCommand cmd1 = new SqlCommand(strSQL1, ConnSql);
cmd1.ExecuteNonQuery();
Response.Write("<script>alert('添加成功!')</script>");
}
dr.Close();
//...前面都一样
SqlDataReader dr = cmd.ExecuteReader();
boolean bExists;
bExists = dr.Read();//如果用户名存在
dr.close();
if (bExists)
{...}
//后面都一样。
if (dr.Read())//如果用户名存在
{
dr.Close();
Response.Write("<script>alert('对不起,用户名已被注册,请换个名称,谢谢!')</script>");
}
if (dr.Read())//如果用户名存在
{
dr.Close();
Response.Write("<script>alert('对不起,用户名已被注册,请换个名称,谢谢!')</script>");
}