Logging in DB table using timestamp

Posted on 2010-01-04
Last Modified: 2013-11-07
I have a web service.. which has a method getStudentDetails(string studentID).
When i give the student id it should retrieve the student details from DB.

Now, whenever that method is called it should log the details of the call in another table.
it should log the studentID, timestamp and no. of times that studentID has been requested.

the "no.of times" column in the table is initially '0'. When the studentID is first requested it should be increase to 1. next time on unitll 5,  each time changing the time stamp to current timestamp.  If the timestamp difference between first request and 6th request is more than 1 hour then the "no of times" should be set to zero...

Please help me wi th the code..
Question by:gautam_reddyc
    LVL 12

    Expert Comment

    I assume you have your table created something like this:
        ID Primary Key Auto Increments
        StudentID (links to Student Table)
        TimeStamp (DateTime)
        NoOfAttempts (int)

       When submitting a record

      1)  DateTime  currentTime  = DateTime.Now;  
      2) Search Table for Student ID
      3) If not found create a new Record in the StudentAccessTable: store TimeStamp to currentTime and set NoOfAttempts to '0'   END
      4) If found AND if NoOfAttempts == 5
          Compare Times:  DateTime diff = currentTime - TimeStamp  if diff.Minutes > 60
          NoOfAttempts = 0  Update Record END
      5) If NoOfAttempts < 5 Update the Record with TimeStamp = currentTime and NoOfAttempts += 1

       That's the Logic Path which is fairly easy to code.



    Author Comment

    thanks... william.. let me try..
    Appreciate your help..
    will let you know once it is done..

    Author Comment

    the code  TimeSpan timeDifference = currentTime.Subtract(oldTime);

    it does not give exact minutes difference..

    suppose oldTime = 1:30:00 11/11/2010

    NewTime = 2:30:00 11/11/2010

    timeDifference should be 120 minutes.. but it does not show that..
    LVL 12

    Accepted Solution

    2:30 -1:30 is 60 minutes

    Author Comment

    i mean.. 2:30 -11:30 should be 180 min .. isnt it?
    LVL 12

    Assisted Solution

    >>  suppose oldTime = 1:30:00 11/11/2010
    >>  NewTime = 2:30:00 11/11/2010

    Says 1:30  .. but yes  11:30 to 2:30 should be 180 Minutes

    Author Comment

    but it shows only 60 minutes..

    and then again it starts with 1 min..

    Is that how TimeSpan is supposed to work??

    this is the code i used to check the time differnce

    TimeSpan timeDifference = currentTime.Subtract(oldTime);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now