请检查代码..... [英] plz chech the code.....

查看:69
本文介绍了请检查代码.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是LastLogin并且RegisterDate未存储在表User
中 我的数据库表是[User]

my problem is LastLogin and RegisterDate is not store in table User
my database table is [User]

ID               int
Email            primarykey varchar(250)     
Password         varchar(250)
Name             varchar(250)                  
Country          varchar(250)
RegisterDate     datetime                   allownulls 
LastLogin        datetime                   allownulls
Description      varchar(50)
ImageName        varchar(1000)


Login.cs


Login.cs

DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        CheckBox chBox = (CheckBox)ctlLogin.FindControl("RememberMe");
        Authenticated = UserAuthenticate(ctlLogin.UserName, ctlLogin.Password);
        e.Authenticated = Authenticated;
        if (Authenticated == true)
        {
            if (chBox.Checked == true)
            {
                Response.Cookies["RFriend_Email"].Value = ctlLogin.UserName;
                Response.Cookies["RFriend_PWD"].Value = ctlLogin.Password;
                Response.Cookies["RFriend_UID"].Value = Session["UserId"].ToString();
                Response.Cookies["RFriend_Email"].Expires = DateTime.Now.AddMonths(6);
                Response.Cookies["RFriend_PWD"].Expires = DateTime.Now.AddMonths(6);
                Response.Cookies["RFriend_UID"].Expires = DateTime.Now.AddMonths(6);
            }
            Response.Redirect("UserDetails.aspx?Id=" + Session["UserId"].ToString());
        }
    }
    private bool UserAuthenticate(string UserName, string Password)
    {
        bool boolReturnValue = false;
        //--------------------------------
        //Check UserID From Config File
        if (UserName == "Rahul" && Password == "Saxena")
        {
            boolReturnValue = true;
            return boolReturnValue;
        }
        else
        {
            //--------------------------------
            SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\WebSite8\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
            dt = new DataTable();
             
            string chkUser = "Select * FROM [User] where Email=''" + UserName + "'' AND Password=''" + Password + "''";
            dt = dbClass.ConnectDataBaseReturnDT(chkUser);
            if (dt.Rows.Count > 0)
            {
                boolReturnValue = true;
                Session["UserId"] = dt.Rows[0]["Id"].ToString();
                SqlCommand cmd = new SqlCommand("UPDATE [User] SET LastLogon = GETDATE() where id= @UserId", conn);
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@UserId";
                param.Value = Session["UserId"];
                cmd.Parameters.Add(param);
                dbClass.ConnectDataBaseToInser(cmd);//there is problem
            }
            return boolReturnValue;
        }

推荐答案

您应该调试并检查命令和参数值.另外,您应该提供参数的类型(请参见SqlDbType属性).

如果问题出现在自定义方法(ConnectDataBaseToInser)内,请首先确保您向其传递了正确的信息,如果可以,请在该方法内进行调试.

旁注:还可以在select语句中使用参数来防止sql注入等.
You should debug and check the command and the parameter values. Also you should provide the type of the parameter (see SqlDbType property).

If the problem happens inside a custom method (ConnectDataBaseToInser) first ensure that you''re passing correct information to it and if that''s ok then debug inside that method.

A sidenote: also use parameters in your select statement to prevent sql injections etc.


这篇关于请检查代码.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆