如何使用VB.NET发送3天的邮件 [英] How to send mail 3 days ones using VB.NET

查看:59
本文介绍了如何使用VB.NET发送3天的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,

我需要每隔3天发送一次使用vb.net的邮件如何发送。我正在使用Windows服务。我在表格中有日期栏。我需要从那天起增加3天..



我尝试了什么:



Dear Friends,
I need to send mail every 3 days ones using vb.net how to send. am using windows service. i have date column in table. i need to add 3 days from that date..

What I have tried:

 If (strComplaintDate.ToString() = DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt")) Then       
                           

     If strCompEmailId <> "" Then                              
   clsInvCmn.StockistSendMail(strCompEmailId, strMessage, "Invoice Complaint", strCCEmailId) 
                                
      End If

 objSBQuery = New StringBuilder
 objSBQuery.Append(" Update DRL_COMPLAINTS_DETAILS_HDR SET DATE_OF_COMPLAINT = DATEADD(day,3,DATE_OF_COMPLAINT) WHERE  COMPLAINTS_DTL_ID='" & strComplaintId & "' ")
clsInvCmn.ExecuteQuery(objSBQuery.ToString)

 End If

推荐答案

由于OP已经表明上面的代码是正确的,我将发布此解决方案来解决问题。 />


OP现在已经添加了 DATEADD()的使用,而不是依赖于 DATE_OF_COMPLAINT + 3 。但是代码仍然不太正确。



如果你打算使用String连接来生成它,那么创建一个StringBuilder是没有意义的。该部分看起来更像这样:
As OP has indicated that "Above code its right" I will post this solution to close off the question.

OP has now added the use of DATEADD() rather than rely on the implicit conversion of DATE_OF_COMPLAINT + 3. However the code is still not quite right.

There is no point in creating a StringBuilder if you are then going to use String concatenation to generate it. That section would look better like this:
objSBQuery = New StringBuilder("Update DRL_COMPLAINTS_DETAILS_HDR SET DATE_OF_COMPLAINT = DATEADD(day,3,DATE_OF_COMPLAINT) WHERE  COMPLAINTS_DTL_ID='"
objSBQuery.Append(strComplaintId)
objSBQuery.Append("' ")

然而,这仍然使代码对SQL注入开放你不应该连接这样的字符串来创建SQL命令。



看起来应该更像:

However, that still leaves the code open to SQL Injection attacks. You should never concatenate strings like that to create SQL commands.

It should look more like:

Dim objSBQuery As String = "Update DRL_COMPLAINTS_DETAILS_HDR SET DATE_OF_COMPLAINT = DATEADD(DD,3,DATE_OF_COMPLAINT) WHERE  COMPLAINTS_DTL_ID=@id"
clsInvCmn.Parameters.AddWithValue("@id", strComplaintId)
clsInvCmn.ExecuteQuery(objSBQuery)

但要做到这一点,你需要实现一些方法将参数传递到 clsInvCmn 类,无论可能是什么。

But to do that you will need to implement some means of passing Parameters into the clsInvCmn class, whatever that might be.


这篇关于如何使用VB.NET发送3天的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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