代码不起作用请检查 [英] code is not working plz check

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

问题描述

当我上传的登录图像未显示在Userdetails页面上时,我开发了注册页面以及登录页面和userdetails页面,这是问题所在,我也给出了userimage文件夹的确切路径,而userimage文件夹具有图像


我的数据库表是User

I develop register page and also login page and userdetails page when i login image that i upload is not display on Userdetails page where is the problem i also give the exact path of userimage folder and userimage folder have the image


MY database table is User

ID                int
Email            primarykey varchar(250)     
Password          varchar(250)
Name              varchar(250)                  
Country           varchar(250)
Gender            varchar(250)
                
RegisterDate         datetime                   allownulls 
LastLogin            datetime                   allownulls

Description           varchar(50)
ImageName             varchar(1000)





<asp:Image ID="Image1" runat="server" Width="258px" />


UserDetails.cs


UserDetails.cs

   DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void GetUserDetails(int id)
    {
        string getUserDetail = "Select ID,Email,Name,Country,Convert(varchar (20), RegisterDate, 106) RegisterDate,Convert(varchar (20), LastLogin, 106) LastLogin ,Description,ImageName FROM [User] where Id='" + id + "'";
        dt = dbClass.ConnectDataBaseReturnDT(getUserDetail);
        if (dt.Rows.Count > 0)
        {
           Image1.ImageUrl = "~/UserImage/" + dt.Rows[0]["ImageName"].ToString();
        }


//above code is not working below i aslo give login page code
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(3);
                Response.Cookies["RFriend_PWD"].Expires = DateTime.Now.AddMonths(3);
                Response.Cookies["RFriend_UID"].Expires = DateTime.Now.AddMonths(3);
            }
            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
        {
            //--------------------------------
            dt = new DataTable();
            SqlConnection con=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");
            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", con);
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@UserId";
                param.Value = Session["UserId"];
                cmd.Parameters.Add(param);
                
            }
            return boolReturnValue;
        }
    }

推荐答案

哦! om56
您忘记执行SqlCommand了.您可以看到这样的示例,
Oh! om56
Your forget to execute your SqlCommand . You can see sample like this,
int totrows;


totrows = cmd.ExecuteNonQuery();
boolReturnValue= (totrows > 0);


最好的问候,
Theingi Win


Best Regard,
Theingi Win


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

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