Hi,

im writing a little app that will run a stroed procedure on my sql database and whip the results (a list of email addresses) in to a new mail items "to" box.

I have my connection strings working and can extract the data fine.
I can create the new mail item fine.
What i cant do is the bit in the middle!! i need to take the results of the SP and populate them in to the "to" field of the mail item.

I have tried various things with no sucess..

This is my code:

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }
        private void button1_Click_1(object sender, EventArgs e)
        {

            #region
            SqlConnection conn = new SqlConnection("Data Source=LIVESERVER;Database=Live_DB;UID=admin;PWD=testing;");
            SqlCommand command = new SqlCommand("SP_email_addresses", conn);
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "emails");
            this.dataGridView1.DataSource = ds;
            this.dataGridView1.DataMember = "emails";
            conn.Close();
            conn.Dispose();
         
            Outlook.Application outlookApp = new Outlook.Application();
            Outlook.MailItem message =
            (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
            message.Subject = "System Message";
            message.Recipients.Add();
              message.Display(true);

           
            #endregion
        }

as you can see there is nothing in "to()" as yet - i can figure out how to take the result of the SP and get them in here..

any help would be great. thanks!

Ive sorted this one now.. for those interested:

(a bit clunky bit het, it works)

Ive changed my stored procedure in SQL to concetenate each of the elements of the email address in to one field and then used coalesce to return all results in to one field using varchar(max)

back over in visual studio I have set the return of the SP populate a richtextbox and then set the mailobject to pickup the "to" field from this textbox.

Job done.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.