VB.Net Send email to each user from MSSQL DB table.

Hi all,

I am stuck trying to loop through an SQL table, finding each user email, and then sending an email to each individual one at a time.
Do you guys have an example on how to do this?  I have the email code that works nicely.  But I need to fill the email address dynamically from the table and send to each user one at a time not as a group.

thank you!
kouts1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
You can use the below code for loop. I have used UserEmailId as column for example.

DECLARE @UserEmailId AS VARCHAR(MAX) = ''
 
IF OBJECT_ID('tempdb..#LoopTableData') IS NOT NULL
    DROP TABLE #LoopTableData
 
SELECT * INTO #LoopTableData FROM YourTableName 

WHILE EXISTS(SELECT TOP 1 1 FROM #LoopTableData)
BEGIN
    SELECT TOP 1 @UserEmailId = UserEmailId FROM #LoopTableData 

	/* YOUR EMAIL CODE Here*/
 
    DELETE FROM #LoopTableData WHERE UserEmailId = @UserEmailId
END
 
 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nitin SontakkeDeveloperCommented:
Where precisely you want to do this? If you are attempting to do this in VB.NET, you obviously will have to do connect to db. Hopefully you know all that stuff, already.

You can then get a SQL DataReader to loop through all the records and send the mail.
0
Pawan KumarDatabase ExpertCommented:
Provided multiple suggestions
Question abandoned.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.