public partial class 注册11111 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid == true)
{
SqlConnection meteor = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["meteor"]);
meteor.Open();
string username = this.TextBox1.Text.ToString();
string password = this.TextBox2.Text.ToString();
string sex = this.RadioButtonList1.SelectedValue;
SqlCommand cmd = new SqlCommand("insert into login(username,password,sex)values('" + username + "','" + password + "','" + sex + "')", meteor);
cmd.ExecuteNonQuery();
meteor.Close();
Response.Write("<script language=javascript>alert('恭喜您,注册成功!')</script>");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string account = this.TextBox1.Text;
if (!validate(account))
Response.Write("您可以使用该用户名!");
else
Response.Write("对不起,该用户名已经存在!");
}
private bool validate(string account)
{
SqlConnection meteor = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["meteor"]);
meteor.Open();
SqlCommand comm = new SqlCommand("select * from login Where
username=('" + TextBox1.Text.ToString().Trim() + "')");
SqlDataReader dr = comm.ExecuteReader();//或者:int count =convert.toInt32(comm.ExcuterSclar());
if (dr.Read())//相应的这里就是 if(cout>0)
{
return false;
}
else
return true;
meteor.Close();
}
}