Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Asp.net c中注册时检查电子邮件是否已注册?_Asp.net_C# 4.0 - Fatal编程技术网

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

在Asp.net c中注册时检查电子邮件是否已注册?,asp.net,c#-4.0,Asp.net,C# 4.0,我正在检查登记名单。当输入的电子邮件存在,然后尝试注册它,直到注册成功,但我不希望这样 protected void btnRegister_Click(object sender, EventArgs e) { if (Page.IsValid) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].Conne

我正在检查登记名单。当输入的电子邮件存在,然后尝试注册它,直到注册成功,但我不希望这样

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...");
        }
    }
如果当前存在SQL注入漏洞,请使用。首选EXISTS而不是COUNT*,并使用.ExecuteScalar返回单个结果而不是数据集。Sql注入错误SqlCommand cmd=new SqlCommand从tblUsers中选择COUNT*,其中Email='+txtEmail.Text+',con;您可以使用CustomValidator检查邮件是否存在。