Private Function GetEmails() As DataSet
Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
Dim connString As String = CType((configurationAppSettings.GetValue("EventConnection", GetType(String))), String)
Dim myConnection As New SqlConnection(connString)Dim CommandText As String = "select email, sqlstring from useremailconfig where alertsenabled = '1'"
Dim mailDataSet As DataSet = New DataSet
Dim Cmd As New SqlDataAdapter(CommandText, myConnection)
Cmd.Fill(mailDataSet)
Return mailDataSet
End FunctionPrivate Function GetEvents(ByVal SQLString As String) As DataSet
Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
Dim connString As String = CType((configurationAppSettings.GetValue("EventConnection", GetType(String))), String)
Dim myConnection As New SqlConnection(connString)
Dim CommandText As String = sqlstring
Dim mailDataSet As DataSet = New DataSet
Dim Cmd As New SqlDataAdapter(CommandText, myConnection)
Cmd.Fill(mailDataSet)
Return mailDataSet
End FunctionPrivate Sub ExecuteEmails()
Dim mailDataSet As DataSet = GetEmails()
Dim mailTable As DataTable = mailDataSet.Tables(0)
For Each row As DataRow In mailTable.Rows
Dim toList As String = CType(row("email"), String)
Dim getstring As String = CType(row("sqlstring"), String)
Dim geteventsDataset As DataSet = GetEvents(getstring)
Dim geteventstable As DataTable = geteventsDataset.Tables(0)
Dim row2 As DataRow
row2 = geteventstable.Rows(0)
Dim eventdate As String = CType(row2("date"), String)
Dim ensemblename As String = CType(row2("ensemblename"), String)
Dim location As String = CType(row2("location"), String)
Dim body As String = eventdate & ensemblename & location
SendEmails(toList, body)
Next
End Sub
The problem with the implementation is this, under the ExecuteEmails subroutine, what if i have more than one row, how would i put that in the body:
Dim row2 As DataRow
row2 = geteventstable.Rows(0)
Dim eventdate As String = CType(row2("date"), String)
Dim ensemblename As String = CType(row2("ensemblename"), String)
Dim location As String = CType(row2("location"), String)
Dim body As String = eventdate & ensemblename & location
Also, what if it returns no rows, i get an exception. Anyway to put more than one row into the body of the email? Thanks!!!
Best,
AsafHello, solved this myself. Thanks anyway.
0 comments:
Post a Comment