Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Help!! Capture user login date and time

Help!! Capture user login date and time

Scheduled Pinned Locked Moved C#
helpcsharpdesignquestion
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    momoo
    wrote on last edited by
    #1

    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!

    V 1 Reply Last reply
    0
    • M momoo

      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!

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • V Vikram A Punathambekar

        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.

        M Offline
        M Offline
        momoo
        wrote on last edited by
        #3

        Hi..Thanks for your reply.. How should i actually write it?? Cheers!

        V 1 Reply Last reply
        0
        • M momoo

          Hi..Thanks for your reply.. How should i actually write it?? Cheers!

          V Offline
          V Offline
          Vikram A Punathambekar
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups