Solved

C# Send email, loop through SQL database to get content

Posted on 2009-05-18
3
539 Views
Last Modified: 2012-05-07
Hi,

I have an issue where I need to loop through SQL to get the following information for an Approve/reject email.

Approval Status, UserTitle, Date Created, and User Notes

The tricky part about this is that this email is generated after a .NET workflow completion and there are several approval stages.  the email will need to have all of the above for each stage and at the same time it will have to properly format the notes with the break points

I am not sure where to begin in this.  I know how to display it in a ASP.NET page by utilizing a dataview and a repeater inside the dataview, but I do not know how to do it in a string that will be processed as an email

thank you for all of your help in advance
0
Comment
Question by:thomasm1948
  • 2
3 Comments
 

Author Comment

by:thomasm1948
Comment Utility
is there someone out there that can help me with this.....

I am really stuck on this and I need some help.  Below is basic code for getting a single row into some labels.  I need to do somthing similar but it needs to be able to go through mutiple rows and send it through email.

The code below with format the notes field correctly just in case there is someone that needs to how to fill a label with sql data

thank you for all of your help in advance
string _Batchid;

        _Batchid = "436";

        System.Data.DataSet SqldataSet1 = new System.Data.DataSet();

        System.Data.SqlClient.SqlConnection SqlCon1 = new System.Data.SqlClient.SqlConnection();

        string sConnSTr1 = null;

        sConnSTr1 = "server=server1;uid=spuser;pwd=password;database=SP_Server";

        SqlCon1.ConnectionString = sConnSTr1;

        SqlCon1.Open();

        System.Data.SqlClient.SqlCommand sqlCommand0 = new System.Data.SqlClient.SqlCommand();

        sqlCommand0.CommandType = System.Data.CommandType.StoredProcedure;

        sqlCommand0.CommandText = "Select_NoteEmail";

        sqlCommand0.Connection = SqlCon1;

        sqlCommand0.Parameters.Add(new System.Data.SqlClient.SqlParameter("@batchid", _Batchid));

        System.Data.SqlClient.SqlDataAdapter sqlDataAdapter0 = new System.Data.SqlClient.SqlDataAdapter(sqlCommand0);

        sqlDataAdapter0.Fill(SqldataSet1);              

        if (SqldataSet1.Tables[0].Rows.Count > 0)

        {

            

            lblApprovalType.Text = SqldataSet1.Tables[0].Rows[0]["NotesType"].ToString();

            lbluserTitle.Text = SqldataSet1.Tables[0].Rows[0]["UserTitle"].ToString();

            lblNotesDet.Text = SqldataSet1.Tables[0].Rows[0]["Notes"].ToString().Replace("\r\n", "<br>");
 

            

        }

        SqlCon1.Close();

Open in new window

0
 

Author Comment

by:thomasm1948
Comment Utility
i found the answer

The following is my code

I will keep this open just in case anyone has a question
int i = 0;

        string _Batchid;

        _Batchid = "159";

        string test = "";

        System.Data.DataSet SqldataSet1 = new System.Data.DataSet();

        System.Data.SqlClient.SqlConnection SqlCon1 = new System.Data.SqlClient.SqlConnection();

        string sConnSTr1 = null;

        sConnSTr1 = "server=server1;uid=spuser;pwd=password;database=SP_database";

        SqlCon1.ConnectionString = sConnSTr1;

        SqlCon1.Open();

        System.Data.SqlClient.SqlCommand sqlCommand0 = new System.Data.SqlClient.SqlCommand();

        sqlCommand0.CommandType = System.Data.CommandType.StoredProcedure;

        sqlCommand0.CommandText = "Select_NoteEmail";

        sqlCommand0.Connection = SqlCon1;

        sqlCommand0.Parameters.Add(new System.Data.SqlClient.SqlParameter("@batchid", _Batchid));

        System.Data.SqlClient.SqlDataAdapter sqlDataAdapter0 = new System.Data.SqlClient.SqlDataAdapter(sqlCommand0);

        sqlDataAdapter0.Fill(SqldataSet1);              

        if (SqldataSet1.Tables[0].Rows.Count > 0)

        {

            for (i = 0; i < SqldataSet1.Tables[0].Rows.Count; i++)

            {
 

                test += "<br />";

                test += SqldataSet1.Tables[0].Rows[i]["NotesType"].ToString() + " ";

                test += SqldataSet1.Tables[0].Rows[i]["UserTitle"].ToString() + "<br /><p>";

                test += SqldataSet1.Tables[0].Rows[i]["Notes"].ToString().Replace("\r\n", "<br>") + "<br />";

            }

            lblNotesDet.Text = test;

        }

        SqlCon1.Close();

Open in new window

0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
Comment Utility
thomasm1948,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now