'ttudy the following code'
Public Function my_account() As Integer
Dim accountNumber As Integer
Try
objconnection.Close()
objconnection.Open()
sql = "select min(accountNo) as ac from Invoices where dateDue='" & Today.Date & "'"
objcommand = New Odbc.OdbcCommand(sql, objconnection)
objdataReader = objcommand.ExecuteReader
objdataReader.Read()
accountNumber = objdataReader("ac")
Catch ex As Exception
MsgBox(ex.Message)
Exit Function
End Try
objconnection.Close()
Return accountNumber
End Function
Public Sub sendmail()
objconnection.Open()
objdataset = New DataSet
Try
objconnection.Close()
objconnection.Open()
sql = "select * from invoices where accountNo='" & my_account() & "' and datedue='" & Today.Date & "'"
objcommand = New Odbc.OdbcCommand(sql, objconnection)
objdataReader = objcommand.ExecuteReader
objdataReader.Read()
If objdataReader.RecordsAffected = False Then
MsgBox("All mails have been sent successfully", MsgBoxStyle.Information, "Wait For Payments")
Exit Sub
objconnection.Close()
Else
sql = "select * from invoices where accountNo='" & my_account() & "' and datedue='" & Today.Date & "'"
objdataAdapter = New Odbc.OdbcDataAdapter(sql, objconnection)
objdataAdapter.Fill(objdataset, "Invoices")
Dim accountNumber As Integer = Convert.ToInt32(objdataset.Tables("Invoices").Rows(0).Item("AccountNo"))
Dim email As String = objdataset.Tables("Invoices").Rows(0).Item("Email").ToString
Dim rpt As New CrNewInvoices
rpt.SetDataSource(objdataset)
rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
rpt.SaveAs("Safariland Wireless Billing", True)
Dim name As String = rpt.Name()
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("setleme@kabakaMutesa.com", "mwenyeji")
SmtpServer.Port = "30"
SmtpServer.Host = "mail.jtl.com"
mail = New MailMessage()
mail.From = New MailAddress("setleme@kabakaMutesa.com")
mail.To.Add(email)
mail.To.Add("mwanadada@gmail.com")
mail.Subject = "Test Mail"
mail.Body = "This is a test of how invoices will be sent"
mail.Attachments.Add(New Attachment(rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat), "billing.pdf"))
SmtpServer.Send(mail)
objconnection.Close()
objconnection.Open()
sql = "update Invoices set dateDue='" & DateAdd(DateInterval.Month, 1, Today.Date) & "' where AccountNo='" & my_account() & "'"
objcommand = New Odbc.OdbcCommand(sql, objconnection)
objcommand.ExecuteNonQuery()
End If
my_invoice()
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
End Sub
My aim was to select an account-number from database table and then use it to generate a crystal report(which in this case is an invoice) and send it to the respective recipient. the problem is that it sends the first invoice to the exact recipient and concatenates the first and the second one(making two invoices in one) and sends to the second recipient, the third one to the individual recipient and the trend continues.
can somebody send me a code that can make it select only one account number,use it to send invoice,and then go for another until all clients whose invoice date is on that particular date? clients have different invoicing dates.