russellmunday
Technical User
I am trying to attach files to an email based on a selection that is stored in a sql table but when i try to loop through whats there i get various build errors.
if anyone has done this or can see where i'm gpoing wrong please help
'connect to database and fill the daaset with the kitnumbers stored in the moving table
Dim wapp As System.Web.Mail.MailMessage
Dim ssql As String
ssql = "select kit from moving"
Dim oconn As New SqlClient.SqlConnection(sconnection)
Dim da As New SqlClient.SqlDataAdapter(ssql, oconn)
Dim ds As New DataSet
'connect and fill
oconn.Open()
da.Fill(ds, "kit")
oconn.Close()
' output results to a datagrid to confirm results so far
dg2.DataSource = ds
dg2.DataBind()
' create the data table
Dim dt As DataTable
dt = ds.Tables("kit")
Dim dr As DataRowCollection
dr = dt.Rows
Dim p As Integer
For p = 0 To dt.Rows.Count
Next
Dim sattach As System.Web.Mail.MailAttachment
Dim i As Integer
ReDim sattach(p)
p = 0
For Each dr In dt.Rows
'create the attachment
sattach(p) = New System.Web.Mail.MailAttachment("c:\attachfiles\" & dr.Item(0) & ".jpg")
p = p + 1
Next
wapp = New System.Web.Mail.MailMessage
With wapp
wapp.From = "webserver@mycompany.com"
wapp.To = "test@mycompany.com"
wapp.Subject = "Thankyou for your order details below"
wapp.Body = "Please see attachments"
wapp.Attachments.Add(sattach)
End With
System.Web.Mail.SmtpMail.SmtpServer = "mysmtpserver"
System.Web.Mail.SmtpMail.Send(wapp)
wapp = Nothing
if anyone has done this or can see where i'm gpoing wrong please help
'connect to database and fill the daaset with the kitnumbers stored in the moving table
Dim wapp As System.Web.Mail.MailMessage
Dim ssql As String
ssql = "select kit from moving"
Dim oconn As New SqlClient.SqlConnection(sconnection)
Dim da As New SqlClient.SqlDataAdapter(ssql, oconn)
Dim ds As New DataSet
'connect and fill
oconn.Open()
da.Fill(ds, "kit")
oconn.Close()
' output results to a datagrid to confirm results so far
dg2.DataSource = ds
dg2.DataBind()
' create the data table
Dim dt As DataTable
dt = ds.Tables("kit")
Dim dr As DataRowCollection
dr = dt.Rows
Dim p As Integer
For p = 0 To dt.Rows.Count
Next
Dim sattach As System.Web.Mail.MailAttachment
Dim i As Integer
ReDim sattach(p)
p = 0
For Each dr In dt.Rows
'create the attachment
sattach(p) = New System.Web.Mail.MailAttachment("c:\attachfiles\" & dr.Item(0) & ".jpg")
p = p + 1
Next
wapp = New System.Web.Mail.MailMessage
With wapp
wapp.From = "webserver@mycompany.com"
wapp.To = "test@mycompany.com"
wapp.Subject = "Thankyou for your order details below"
wapp.Body = "Please see attachments"
wapp.Attachments.Add(sattach)
End With
System.Web.Mail.SmtpMail.SmtpServer = "mysmtpserver"
System.Web.Mail.SmtpMail.Send(wapp)
wapp = Nothing