关于用户注册的处理问题.

来源:百度知道 编辑:UC知道 时间:2024/05/22 19:15:58
private void ExecuteSql(string sql)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
con.Open();
SqlCommand com = new SqlCommand(sql, con);
com.ExecuteNonQuery();
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string sql = "insert into users(username,password,sex,email) values('" + txtUserName.Text + "','" + txtUserPwd + "','" + RadioButtonList1.Text + "','" + txtEmail.Text + "')";
if (this.ExecuteSql(sql))
{
Response.Write("注册成功!请<a herf=Default.aspx>登录</a>");
}
else
{
Response.Write("注册失败!");
}

private int ExecuteSql(string sql) //返回整型
{
int result=0;
try{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
con.Open();
SqlCommand com = new SqlCommand(sql, con);
result=com.ExecuteNonQuery();
}catch{
//你的逻辑
}finally{
con.Close();
}
return result;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string sql = "insert into users(username,password,sex,email) values('" + txtUserName.Text + "','" + txtUserPwd + "','" + RadioButtonList1.Text + "','" + txtEmail.Text + "')";
if (this.ExecuteSql(sql)>0)//在这儿判断是否执行成功
{
Response.Write("注册成功!请<a herf=Default.aspx>登录</a>");
}
else
{
Response.Write("注册失败!");
}
}
}