在Asp.net c#中注册时,检查电子邮件是否注册?

时间:2016-04-04 10:09:29

标签: asp.net c#-4.0

我正在尝试检查whilist注册。如果存在已输入的电子邮件,然后尝试注册,直到注册成功,但我不想这样做。

protected void btnRegister_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {

            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
            con.Open();
            SqlCommand  cmd = new SqlCommand ("Select count(*) from tblUsers where Email = '" + txtEmail.Text + "' ", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet  ds = new DataSet();
            da.Fill(ds);


            if (ds.Tables[0].Rows.Count > 0)
            {
                p.UserName = txtUsername.Text;
                p.Email = txtEmail.Text;
                p.DOB = Convert.ToDateTime(txtDob.Text);
                p.Password = txtPass.Text;
                p.InsertUser(p);
                Response.Write("Registration Successfull..");
            }
            else {
                Response.Write("This Email is Already Exist...!!");
            }
        }
        else
        {
            Response.Write("Fail...");
        }
    }

0 个答案:

没有答案