如何使用SQL Server和asp.net通过数据库自动发送提醒用户 [英] how to send reminders to users automatically through database using SQL server and asp.net
问题描述
假设有没有。用户谁想要通过数据库中自动使用SQL Server和asp.net之前数据库中给定日期两天发送提醒(电子邮件)。
请帮助..
假设我有表 USER_DB
包含像
Auto_id,USER_ID,EMAIL_ID,Inspection_Date,IsInterested
因此,对于上面列中的值
1,用户1,一个@ yahoo.com,30-01-2013,是
2,用户2,B @ yahoo.com,2013年1月2日,是
3,用户3,C @ yahoo.com,30-01-2013,是
4,USER4,D @ yahoo.com,2013年1月1日,是
如果用户有兴趣看到详细的内容,然后在 IsInterested
列中包含值是
则电子邮件警报应该去前2天给予 Inspection_Date
自动...
怎么办呢?
列表< INT> CustomersToEmail =新的List< INT>();SqlDataReader的RDR = NULL;
VAR连接=新的SqlConnection(连接字符串);
VAR CMD =新的SqlCommand(SELECT * FROM USER_DB连接);RDR = cmd.ExecuteReader();而(rdr.Read())
{
DateTime的DT =(DateTime的)RDR [Inspection_Date];
INT客户id =(int)的RDR [user_ID的]; 如果((DT - DateTime.Now).TotalDays&下; = 2)
{
CustomersToEmail.Add(客户ID);
}}EmailAllCustomers(CustomersToEmail);
以上code版本是在检验日期2天的客户名单。我建议你添加一个布尔值列的人是否已通过电子邮件发送与否,prevent重复。您可以在一个计时器循环通过计划窗口服务调用此方法你的的Global.asax
。
Suppose there are no. of users who wants to send the reminders (Email) before two days of given date in database automatically through database using SQL Server and asp.net.
Please help..
Suppose I have table user_db
which contains columns like
Auto_id, user_id, email_id, Inspection_Date, IsInterested
So the values for above columns are
1,user1,a@yahoo.com,30-01-2013,Yes
2,user2,b@yahoo.com,01-02-2013,Yes
3,user3,c@yahoo.com,30-01-2013,Yes
4,user4,d@yahoo.com,01-01-2013,Yes
If user is interested to see the details then value in IsInterested
column contains Yes
then the email alerts should go before 2 days of given Inspection_Date
automatically...
How to do it?
List<int> CustomersToEmail = new List<int>();
SqlDataReader rdr = null;
var connection = new SqlConnection("Connection String");
var cmd = new SqlCommand("SELECT * FROM user_db", connection);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
DateTime DT = (DateTime)rdr["Inspection_Date"];
int CustomerID = (int)rdr["user_id"];
if ((DT - DateTime.Now).TotalDays <= 2)
{
CustomersToEmail.Add(CustomerID);
}
}
EmailAllCustomers(CustomersToEmail);
The above code builds a list of customers that are within 2 days of inspection date. I suggest you add a boolean column for whether the person has been emailed or not, to prevent duplicates. You can call this method via a scheduled windows service on a timer loop in your global.asax
.
这篇关于如何使用SQL Server和asp.net通过数据库自动发送提醒用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!