Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
tablename User

ID int
Email varchar(500)
Password varchar(500)
Name varchar(500)
Country varchar(500)
LastLogin datetime
RegisterDate datetime
Description Varchar(500)
ImageName varchar(500)

code is
C#
    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();
        string que = "UPDATE [User] SET LastLogin = GETDATE() where Id=" + Session["UserId"].ToString();

        DateTime registerDate = (DateTime)dt.Rows[0]//specified cast is not ["RegisterDate"];valid
        dbClass.ConnectDataBaseToInsert(que);
    }
    return boolReturnValue;
}
Posted
Updated 24-Apr-11 3:00am
v3
Comments
Ed Nutting 24-Apr-11 9:00am    
Edited for code formatting but: What's your question? You can't expect people to try and work out what your asking from as little as an incomplete commented error message.
ambarishtv 24-Apr-11 11:09am    
dt.Rows[0]["Id"].ToString() is wrong

For DateTime validation..try this
DateTime temp;
if(DateTime.TryParse(dt.Rows[0].ItemArray[6].toString(), out temp))
{
//Valid date
}
else
{
//Invalid date
}
 
Share this answer
 
v3
Comments
Ed Nutting 24-Apr-11 9:12am    
Good, my 4. But if you look at his code, as I pointed out, it should not be dt.Rows[0] but more likely dt.Rows[6], from looking at his table description.
ambarishtv 24-Apr-11 9:18am    
Yes,URgt
Kim Togo 24-Apr-11 10:39am    
My 3.
There is no need to convert a column of type datetime to a string and then back again to a Datetime.
But this is a repost, 2 times.

http://www.codeproject.com/Answers/186130/register-date-code.aspx
http://www.codeproject.com/Answers/185827/error-not-as-valid-datetime.aspx
From looking at your code it seems like you've made a blinding mistake. First you use dt.Rows[0] to set the Session["UserId"] and then you try and use it again to set registerDate. Surely you're not using a date time as the user's Id? And if you are, have you bothered trying to check what type dt.Rows[0] is? Perhaps it's a string and you need to use DateTime.Parse().
 
Share this answer
 
v2
Change this:

DateTime registerDate = (DateTime)dt.Rows[0]//specified cast is not ["RegisterDate"];valid


To this:

DateTime registerDate = (DateTime)dt.Rows[0]["RegisterDate"];


Your "dt.Rows[0]" is wrong. First give row index, then column index.
 
Share this answer
 
v2
Comments
ambarishtv 24-Apr-11 10:57am    
thats ok
Kim Togo 24-Apr-11 15:15pm    
ok to what? :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900