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

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

问题描述

我开发了三个页面login.csregister.csuserdetails.cs.登录我注册时上传的图像时,我的注册页面工作正常,用户详细信息页面上未显示
UserDetails代码为

I develop three pages login.cs, register.cs and userdetails.cs. My register page is working fine when I login in image that I upload when I register is not display on userdetails page
UserDetails code is

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[11]["ImageName"].ToString();
        }

登录代码为


login code is


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;
        }
    }


表名是用户

我的数据库表是User


Table name is User

MY database table is User

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



Databaseclass.cs



Databaseclass.cs

SqlDataAdapter da;
    SqlConnection con;
    SqlCommand cmd = new SqlCommand();
    DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    public DataBaseClass()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public void ConnectDataBaseToInsert(string Query)
    {
        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");
        cmd.CommandText = Query;
        cmd.Connection = con;
        da = new SqlDataAdapter(cmd);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }
    public DataSet ConnectDataBaseReturnDS(string Query)
    {
        ds = new DataSet();
        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");
        cmd.CommandText = Query;
        cmd.Connection = con;
        da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        return ds;
    }
    public DataTable ConnectDataBaseReturnDT(string Query)
    {
        dt = new DataTable();
        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");
        cmd.CommandText = Query;
        cmd.Connection = con;
        da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        con.Open();
        cmd.ExecuteNonQuery();//error is here 
        con.Close();
        return dt;
    }

推荐答案

正如约翰·西蒙斯(John Simmons)所指出的,请指出并描述问题.另一件事是,我不明白为什么您要对日期/年/月有不同的字段.重新考虑使用date 数据类型.
As John Simmons pointed out, please pinpoint and describe the problem. Another thing is that I don''t understand why do you have separate fields for date/year/month. Reconsider using date datatype.


您发布了太多代码,没有指定要获取的错误.

尝试在代码周围放置try/catch块,以查看实际的异常是什么.它应该具有相当的描述性.
You posted too much code, didn''t specify what error you''re getting.

Try putting try/catch blocks around your code to see what the actual exception is. It should be fairly descriptive.


在您的用户详细信息中,您可以通过以下方式设置图像:

In your user details you set the image with this:

Image1.ImageUrl = "~/UserImage/" + dt.Rows[11]["ImageName"].ToString()



使用此方法,数据表的行集合中的索引将返回第12行.

我猜您只打算从查询中返回一行,因此"dt.Rows [11]"应为"dt.Rows [0]".



Using this, the index into the rows collection in your datatable is returning the 12th row.

I''m guessing you are only intend to return a single row from the query, so "dt.Rows[11]" should be "dt.Rows[0]".


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

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