使用loop else stmt为生日和婚礼日发送短信 [英] sending sms for birthday and wedding day wish using loop else stmt

查看:41
本文介绍了使用loop else stmt为生日和婚礼日发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DOB    datetime 
WEdding datetime 




Sql = "select s.Name,s.DOB,s.Mobileno,s.Weddingday from BirthDayWish s where s.Active <> 'D'";
                    Sql = Sql + " and year(DOB) <> '1900'";
                    Sql = Sql + " and month(DOB) = month('" + Convert.ToDateTime(CurDate) + "') and day(DOB) = day ('" + Convert.ToDateTime(CurDate) + "') ";
                    Sql = Sql + " or year(Weddingday) <> '1900'";
                    Sql = Sql + " or month(Weddingday) = month('" + Convert.ToDateTime(CurDate) + "')  or day(Weddingday) = day ('" + Convert.ToDateTime(CurDate) + "')";







发送短信给生日和婚礼当天,



i必须使用循环条件查询申请并发送短信。



如果年份不等于1900 DONT首先发送短信到生日愿意

然后我使用其他stmt如果年份不等于1900 DONT发送短信到婚礼。

同样

如果年份<>到1900从数据库发送短信DOB日期并发送短信到生日

然后我用其他stmt我年<> 1900发送短信到婚礼。



i从上面的查询发送上述查询如何申请我的其他stmt。



请从我上面的查询中发送else loop stmt查询。



请帮帮我。



i希望在from1.cs页面中写入查询




sending sms for birthday and wedding day,

i have to use loop condition query apply and send the sms.

if year not equal to 1900 DONT send sms first to birthdaywish
then i use else stmt if year not equal to 1900 DONT send sms to wedding.
likewise
if year <> to 1900 send sms DOB date from database and send sms to birthday
then i use else stmt i year <> 1900 send sms to wedding.

i send the above query from the above query how to apply my else stmt.

please send the else loop stmt query from my above query.

please help me.

i want to write the query in from1.cs page

推荐答案

我不确定我完全理解你的问题,但有一点,请为了你的同事请或者任何可怜的灵魂都可能落后于你,不要写那样的sql。当你所发布的内容被写入时,它是一个难以维护的东西。不是说我的也很完美(并不是因为我把它扔得太快)但是为了你未来的理智和你周围的人,重构你的sql。



现在我不确定我完全理解你的问题,但我看到了你的日期比较的一些问题,我认为需要额外的括号,以便你的查询工作。我还在数据读取器中的c#循环中汇总了一个示例,然后您可以从查询中提取值并执行您尝试从那里做的任何逻辑。



Im not sure i quite understand your question, but one thing, please please please for the sake of your coworkers or whatever poor soul may come behind you do not write your sql like that. It is a NIGHTMARE to maintain when written like what you have posted. Not saying mine is perfect either (and its not going to be for how fast i threw this together) but for your future sanity and those around you, refactor your sql.

Now im not sure i entirely understand your question but i saw some issues with your date comparison that i thought needed extra parenthesis around it in order for your query to work. I''ve also thrown together a sample in c# looping on the data reader where you can then pull values from your query and do whatever logic you are trying to do from there.

string ConnectionString = String.Format(@"Data Source = {0};User Id={1}; password={2}; Initial Catalog = {3};",
							ConfigurationManager.AppSettings["DB_Server"],
							ConfigurationManager.AppSettings["DB_User"],
							ConfigurationManager.AppSettings["DB_Pass"],
							ConfigurationManager.AppSettings["DB_Name"]);
															
string query = string.Format(@"SELECT 
			            S.Name,
				    S.DOB,
				    S.Mobileno,
				    S.Weddingday 
			       FROM 
                                    BirthDayWish AS S 
                               WHERE S.Active <> 'D'
                               AND 
                                   year(DOB) <> '1900'
                               AND 
				   (month(DOB) = month('{0}') AND day(DOB) = day ('{0}')) 
			       OR 
				   (year(Weddingday) <> '1900' AND month(Weddingday) = month('{0}') AND day(Weddingday) = day ('{0}'))", DateTime.Now);	
							
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
SqlCommand queryCMD = new SqlCommand(query, connection);
SqlDataReader queryReader = queryCMD.ExecuteReader();
while (queryReader.Read())
{
	//Do Logic Here To Handle SMS
	//Could also handle WHERE Criteria in your sql here as well if you wanted
	//ex:
	/*
		if(DateTime.Now.Year != 1900)
		{
			//Send SMS
		}
	
	*/
}


这篇关于使用loop else stmt为生日和婚礼日发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆