Send email from dataset rows (Resolved)
I am trying to send emails for records found in my dataset
VB Code:
Private Sub SendConfirmationEmail_x()
Dim getZip As String = txtZip.Text
Dim getRad As Integer = CInt(ddlRadius.SelectedValue)
Dim myDS As DataSet = GetUE_ZipRadius(getZip, getRad)
Dim intCountDs As Integer = DataList1.Items.Count
Dim myDR As DataRow
With myDS.Tables("ZipCodes")
For Each myDR In myDS.Tables
Dim strMailTo As String = myDS.Tables(1).ToString
Dim strMailServer As String = "mail.*******.com"
Dim strMailFrom As String = "admin@*******.com"
Dim strMailSubject As String = "Test Email"
Dim strMailMsg As String = "Mail Messege"
Dim MailObj As New System.Net.Mail.SmtpClient
MailObj.Host = strMailServer
MailObj.Send( _
strMailFrom, _
strMailTo, _
strMailSubject, _
strMailMsg)
Next
End With
myDS.Dispose()
End Sub
I am getting Unable to cast object of type 'System.Data.DataTable' to type 'System.Data.DataRow'. and then it highlights this part of the code
VB Code:
Line 154: End If
Line 155: With myDS.Tables("ZipCodes")
Line 156: [b]For Each myDR In myDS.Tables[/b]
Line 157: Dim strMailTo As String = myDS.Tables(1).ToString
Line 158: Dim strMailServer As String = "mail.uncleedsoil.com"
What am I doing wrong?
Re: Send email from dataset rows
Change the offending line as follows:
VB Code:
For Each myDR In myDS.Tables.Rows
Better yet because of your with statement try this:
Re: Send email from dataset rows