Help!! Capture user login date and time
-
Hi.... I'm currently doing a program using C# web application. I have some problem going on. I design a login web page, if i now need to capture the time and the date of the user once they login, how the code should be written??Below is my code: SqlConnection conn=new SqlConnection("my connection string"); string strSql="select count(*) from Particulars where UserName=@UserName and Password=@Password"; conn.Open(); SqlCommand command=new SqlCommand(strSql,conn); command.Parameters.Add("@UserName", SqlDbType.NVarChar,50); command.Parameters["@UserName"].Value=TBUserName.Text; command.Parameters.Add("@PassWord", SqlDbType.NVarChar,50); command.Parameters["@Password"].Value=TBPassword.Text; if(int.Parse(command.ExecuteScalar().ToString())>=1) { Response.Redirect("menu.aspx"); //exist,successful; } else { Response.Redirect("login.aspx"); //not exist,failed! } conn.Close(); Anyone can help me take a look and tell me how should i write the code to capture the user login time and date. Thanks for your help! Cheers!
-
Hi.... I'm currently doing a program using C# web application. I have some problem going on. I design a login web page, if i now need to capture the time and the date of the user once they login, how the code should be written??Below is my code: SqlConnection conn=new SqlConnection("my connection string"); string strSql="select count(*) from Particulars where UserName=@UserName and Password=@Password"; conn.Open(); SqlCommand command=new SqlCommand(strSql,conn); command.Parameters.Add("@UserName", SqlDbType.NVarChar,50); command.Parameters["@UserName"].Value=TBUserName.Text; command.Parameters.Add("@PassWord", SqlDbType.NVarChar,50); command.Parameters["@Password"].Value=TBPassword.Text; if(int.Parse(command.ExecuteScalar().ToString())>=1) { Response.Redirect("menu.aspx"); //exist,successful; } else { Response.Redirect("login.aspx"); //not exist,failed! } conn.Close(); Anyone can help me take a look and tell me how should i write the code to capture the user login time and date. Thanks for your help! Cheers!
Surely you should be able to use
DateTime.Now
to capture the current date and time? Once you get this object, you can use its ToString() methods to extract the date and time in any format you want. HTH. :) Cheers, Vikram.
"When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
-
Surely you should be able to use
DateTime.Now
to capture the current date and time? Once you get this object, you can use its ToString() methods to extract the date and time in any format you want. HTH. :) Cheers, Vikram.
"When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
-
A simple lookup on MSDN will help you. I suggest you do that in future before asking because * you learn better that way * somebody is not always going to be around to help you Please don't think I'm being harsh or condescending. :) This is what you're supposed to do, if you want the date as a string in the DD/MM/YYYY format:
DateTime dt = DateTime.Now;
string todaysDate = dt.ToString("dd/MM/yyyy");Now you can do whatever you want with this string. Retrieving the time is very similar, just change the format string in the call to
ToString()
. HTH. :) Cheers, Vikram.
"When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.