C#电子邮件验证

时间:2019-12-29 19:11:13

标签: c#

我无法解决显示消息的问题。当我调试程序时,它将跳到“其他”部分。那么我的``如果''部分有什么问题呢?我正在进行电子邮件验证,激活码已发送到我的电子邮件地址,并且如果激活码与中的数字相同,我会尝试在文本框中输入激活码。文本框,然后它将显示严格状态并修改状态,从而在数据库中得到验证。但是现在我在文本框中输入了正确的激活码,它还显示了错误。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace test2
{
public partial class ActivateEmail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label2.Text = "Your Email is " + 
  Request.QueryString["emailaddress"].ToString() + " ,Kindly Check Your 
   Mail Inbox For Activation Code";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string cs = Global.CS;
        String myquery = "Select *From EmailDetail where emailaddress='" + Request.QueryString["emailaddress"] + "'";
        SqlConnection con = new SqlConnection(cs);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = myquery;
        cmd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            String activationcode;
            for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                activationcode = ds.Tables[0].Rows[i]["activationcode"].ToString();

               if (activationcode == txtCode.Text )
                {                      
                    Label3.Text = "Your Email Has Been Verified Successully";
                    Changestatus();
                    return;
                }
                else
                {
                System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "alert('Fail');", true);                       
                }
            }
        }
        else
        {
            System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "alert('Fsdfdsfdsfl');", true);
        }
        con.Close();
    }

    public void Changestatus()
    {

        try
        {
            string cs = Global.CS;
            String updatedata = "Update EmailDetail set status='Verified' where emailaddress='" + Request.QueryString["emailaddress"] + "'";
            SqlConnection con = new SqlConnection(cs);
            con.Open();
            SqlCommand cmd = new SqlCommand(updatedata,con);

            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception)
        {
            System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "alert('Fail');", true);
        }
    }
}

}

0 个答案:

没有答案