Mano
Mano

Reputation: 67

Automatically update record of SQL data after 1 hour using C#

I have a page created in ASP.NET with a login page. I have made an option to activate something after logging in. This value is by default set to "False" in SQL database. When the user clicks on activate button then this column is updated to "True" using a query in C#.

My problem is that after updating the value to "True", after 1 hour this column should be automatically updated as "False" even if the user is logged in or not. How can I do this using C# and SQL?

Upvotes: 0

Views: 1771

Answers (3)

Zulqarnain Jalil
Zulqarnain Jalil

Reputation: 1681

Simply Follow The Steps Here You just need to change the query According to your need and set the schedule at every 1 hour

or you can create trigger on update and add this code for delay of an hour

DECLARE @MyDateTime DATETIME
SET @MyDateTime = DATEADD(HOUR,1,GETDATE())
WAITFOR TIME @MyDateTime
SELECT GETDATE() CurrentTime

Upvotes: 0

KumarHarsh
KumarHarsh

Reputation: 5094

Alter table to add one more column called ActiveDate datetime

whenever that column is true or false,simply set the current time in ActiveDate

Now Create a Scheduler. My example consist of window schedular which run every 1 hour

Make a programme in console application that you would simply invoke your proc.

This proc make all true to false.

Convert this console to exe and attach to Window Schedular.

Upvotes: 1

Zohar Peled
Zohar Peled

Reputation: 82474

The simplest solution would be to change the data type to datetime, and set it's value to the last time the user clicked the activate button. Then you don't need to automatically update it later on, you only need to check if it's value is within the last hour.

Upvotes: 3

Related Questions