Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 26-Apr-17 3:16am
v6
Comments
ZurdoDev 26-Apr-17 8:05am    
Write a Windows service to do it.
Vivek.anand34 26-Apr-17 8:19am    
I updated question. plz. see it.
ZurdoDev 26-Apr-17 8:20am    
Look at sql's DATEADD() function
Vivek.anand34 26-Apr-17 8:22am    
what i have tried updated...
[no name] 26-Apr-17 8:25am    
Then please update your posting to include an actual question and a description of the problem with your code. We aren't mind readers.

1 solution

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:
VB
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("' ")
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:
VB
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)
But to do that you will need to implement some means of passing Parameters into the clsInvCmn class, whatever that might be.
 
Share this answer
 
Comments
Vivek.anand34 27-Apr-17 4:55am    
Ok.. I need send mail based on this date..........
CHill60 27-Apr-17 4:59am    
I assumed that was what clsInvCmn.StockistSendMail did as you are already checking If (strComplaintDate.ToString() = DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt")) Then
Vivek.anand34 27-Apr-17 5:19am    
Yes..... its right.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900