简体   繁体   中英

How to automate a task in a ASP.NET website in C#

NET. I want to modify a field "Age" for all account holders in my MYSQL database once an year. Is there any way to automate this task?

I know this doesn't directly answer your question, but if you want to update Age every year, would it not make more sense to record their DateOfBirth and then calculate their age from that?

However, to answer your question, you could look at using the TaskScheduler class.

You can use the event scheduler to achieve the above purpose in Mysql. No need to write down the code in frontend, do the job in backend.

To create an event, you can use the create event statement. Here is an explanation with example.

Something like this:

CREATE EVENT CalculateAge_Event
     ON SCHEDULE EVERY 1 YEAR
     DO 
Update myschema.Employee Set Age = DATEDIFF(NOW(),DateOfBirth);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM