Webmaster Forums Banner Professional Hosting from Just Host
Welcome Guest Search | Active Topics | Members | Log In | Register

looping threw sql database and sending email Options
hari
Posted: Thursday, May 22, 2008 11:06:37 AM
Rank: Advanced Member
Groups: Member

Joined: 3/31/2008
Posts: 61
Points: 183
Location: NY
I need a way to loop threw a sql database and send email to the email address in the sql database. Here My connection string
Code:
Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("UserDataDB").ToString()Dim con As New SqlConnection(ConnectionString)

con.Open()

Dim CommandText As String = "SELECT NameToUse, EmailAddress FROM NewsLetter"

Dim cmd As SqlCommand = Nothing
cmd = New SqlCommand(CommandText)

cmd.Connection = con

Dim rdr As SqlDataReader = Nothing

rdr = cmd.ExecuteReader()

rdr.Read()
Dim Name As String = rdr("NameToUse")

Dim EmailAddress As Integer = rdr("EmailAddress")

'Loop threw the database and return each record one at a time

SendEmail(Name, EmailAddress)

rdr.Close()

con.Close()
Sponsor
Posted: Thursday, May 22, 2008 11:06:37 AM
ca4nul
Posted: Thursday, May 22, 2008 11:07:48 AM

Rank: Advanced Member
Groups: Member

Joined: 11/9/2007
Posts: 223
Points: 575
Location: UK
Did you try something like this?



Code:
While rdr.Read()

  Dim Name As String = rdr("NameToUse")
  Dim EmailAddress As Integer = rdr("EmailAddress")

  SendEmail(Name, EmailAddress)

End While


Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by HaqTech.Com
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.303 seconds.