将sql字段值声明为aspx页面

时间:2016-05-22 13:56:14

标签: c# asp.net gridview activation

我已经建立了一个信用申请页面,其中用户可以申请价值/金额。我已经实现了应该首先通过电子邮件激活激活它,然后再将数据放入管理页面进行查看和批准。

我已经创建了一个“已激活”字段,在用户点击了他/她的电子邮件地址上的链接之前它是空的,当用户点击它时它变为“1”。 这是代码:

                            protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string constr = "Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True";
            string activationCode = !string.IsNullOrEmpty(Request.QueryString["ActivationCode"]) ? Request.QueryString["ActivationCode"] : Guid.Empty.ToString();
            using (SqlConnection con = new SqlConnection(constr))
            {
                SqlCommand Activate = new SqlCommand("SELECT UserId FROM CRActivation WHERE ActivationCode = @ActivationCode");
                Activate.Parameters.AddWithValue("@ActivationCode", activationCode);
                Activate.Connection = con;
                con.Open();
                string storedUserId = Activate.ExecuteScalar().ToString();
                con.Close();
                using (SqlCommand cmd = new SqlCommand("DELETE FROM CRActivation WHERE ActivationCode = @ActivationCode"))
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@ActivationCode", activationCode);
                        cmd.Connection = con;
                        con.Open();
                        int rowsAffected = cmd.ExecuteNonQuery();
                        con.Close();
                        if (rowsAffected == 1)
                        {
                            SqlCommand userCmd = new SqlCommand("UPDATE CreditRequests SET Activated = 1 WHERE ID = " + storedUserId);
                            userCmd.Connection = con;
                            con.Open();
                            userCmd.ExecuteNonQuery();
                            con.Close();

                            ltMessage.Text = "Credit Request Submitted.";
                        }
                        else
                        {
                            ltMessage.Text = "Invalid Activation code.";
                        }
                    }
                }
            }
        }

我想要发生的是继续“激活”字段并创建一个if语句,如果它是1,它将显示在我的gridview中。

这里是gridview代码:

protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["IslandGasAdminFM"] != null)
        {
            bindgrid();
            Label1.Text = "- Finance Manager";
        }
        else
        {
            Response.Write("<script>alert('Finance Manager credentials needed'); window.location.href='LogIn.aspx';</script>");
        }
    }

类似的东西:

if(Activated==1)
{
bindgrid();
}

任何帮助或技巧都会有很大的帮助。

0 个答案:

没有答案