[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Logging in DB table using timestamp

Posted on 2010-01-04
7
Medium Priority
?
254 Views
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 2...so 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..
0
Comment
Question by:gautam_reddyc
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 26174093
I assume you have your table created something like this:
 
    StudentAccessTable
    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.

wc






   
   
0
 

Author Comment

by:gautam_reddyc
ID: 26181647
thanks... william.. let me try..
Appreciate your help..
will let you know once it is done..
0
 

Author Comment

by:gautam_reddyc
ID: 26204237
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..
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 12

Accepted Solution

by:
williamcampbell earned 2000 total points
ID: 26204340
2:30 -1:30 is 60 minutes
0
 

Author Comment

by:gautam_reddyc
ID: 26204670
i mean.. 2:30 -11:30 should be 180 min .. isnt it?
0
 
LVL 12

Assisted Solution

by:williamcampbell
williamcampbell earned 2000 total points
ID: 26204729
>>  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
0
 

Author Comment

by:gautam_reddyc
ID: 26204781
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);
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 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