Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

database value as email file name 1

Status
Not open for further replies.

russellmunday

Technical User
Jul 24, 2003
87
GB
I have a prgram that stores infromation in an sql table through the program until the final page where the collected data is then used to place an order.
I want to be able to use the kit number values as part of the filename that i can then attach to an email.
for example if i had the kitnumbers rm001 and rm003 in the database i would want to send files named rmoo1.jpg and rm003.jpg as the email attachments.
I am ok on creating the filename and attaching it to the email for sending but i need help on getting just the information i need from the database to something i can use, in the past i have used a text box to create the file name eg. attachments.add "c:\myfiles\" & textbox1.text & ".jpg".

I will not know how many kits have been chosen so i need some way of looping through them. the database table column called kit holds the kitnumbers i will want to use.

any help appreciated
 
select kitnumbers from kits
where <something here to restrict the rows coming back>


Load it into a dataset

Loop through the dataset and do what ever you need to do with the names.
 
I understand the sql query but do you have any examples on looping through the dataset?
Thanks
 
Loop Through Data From A Database" - faq855-5662

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
OK i have this so far but it may be completley off mark
the loop through seems to work if i use the response.write as in the example but i am not sure where to go from here.

Private Sub sndtorep()
'code here sends email to factory with attachments
Dim wapp As System.Web.Mail.MailMessage
Dim sto As String
Dim ssub As String
Dim sbody As String
Dim oconn As SqlClient.SqlConnection
Dim da As SqlClient.SqlDataAdapter
Dim dt As New DataTable
Dim dr As DataRow
Dim ssql As String = "select kit from moving"
Dim i As Integer

oconn = New SqlClient.SqlConnection(sconnection)
oconn.Open()
da = New SqlClient.SqlDataAdapter(ssql, oconn)
da.Fill(dt)
Dim sattach(i) As String

For i = 1 To 10
For Each dr In dt.Rows

'create the attachment
sattach(i) = New System.Web.Mail.MailAttachment("f:\SOFTWARE\gb" & dr.Item & ".plt")
Next
Next

'Dim sattch(i) As New System.Web.Mail.MailAttachment("f:\SOFTWARE\gb" & dr.Item & ".plt")

wapp = New System.Web.Mail.MailMessage
With wapp
wapp.From = "webserver@mydomain.com"
wapp.To = emailtxt.Text
wapp.Bcc = "factory@mydomain.com"
wapp.Cc = "rep@mydomain.com"
wapp.Subject = "Thankyou for your order details below"
wapp.Body = "Please see attachments"
'wapp.Attachments.Add(attachment)
wapp.Attachments.Add(sattach(i))

End With
System.Web.Mail.SmtpMail.SmtpServer = "post.demon.co.uk"
System.Web.Mail.SmtpMail.Send(wapp)
wapp = Nothing

End Sub
 
I'm not sure why you do your loop before setting up the email. Once you get to adding you attachments, I would llop through the datatable then i.e.
Code:
        Dim mAttach As System.Web.Mail.MailAttachment
        For Each dr In dt.Rows
            'add each attachment
            mAttach = New System.Web.Mail.MailAttachment("f:\SOFTWARE\gb" & dr.Item & ".plt")
            wapp.Attachments.Add(mAttach)
        Next

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top