Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add multiple email address receipients retrieved from MySQL?
    text
    copied!<p>I'm getting an error on this line below :-</p> <p>email = myDataReader.GetValue(i).ToString();</p> <p>What I'm trying to do is just retrieve multiple email addresses from MySQL and send email.</p> <p>Based on the example that I have found, it stores in the arraylist, but in my case it gives me error.</p> <p>I have look on the Google but still not able to correct the error.</p> <p>Could some one help me out please ? Thanks.</p> <pre><code> protected void searchEmail () { MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem"); con.Open(); MySqlCommand cmd = new MySqlCommand("SELECT cusEmail,cusFName,newBalance FROM monthlytracker WHERE MONTH(paymentDate)='" + mm + "' AND YEAR(paymentDate)='" + year + "'AND status='" + Unpaid + "'",con); MySqlDataReader myDataReader = cmd.ExecuteReader(); //ArrayList list_emails = new ArrayList(); int i = 0; //string email = string.Empty; List&lt;CustInfo&gt; list_emails = new List&lt;CustInfo&gt;(); CustInfo customer; while (myDataReader.Read()) { //list_emails.Add(myDataReader.GetValue(i).ToString());//add to array list //i = i++; //increment or ++i list_emails.Add(new CustInfo { Email = myDataReader.GetValue(0).ToString(), Name = myDataReader.GetValue(1).ToString(), Balance = myDataReader.GetValue(2).ToString() }); } con.Close(); //Close connection foreach (CustInfo cus in list_emails) { var fromAddress = new MailAddress("veolbakhda@gmail.com", "Shilpesh"); var toAddress = new MailAddress(cus.Email); const string fromPassword = "XXXXXXXX"; string fullSubj = "Payment Reminder - Madu D. Trading (" + month + " , " + year + ")"; //const string subject = fullSubj; //const string body = "Body"; string body1 = cus.Name; string body2 = cus.Balance; string bodyfull = body1 + body2; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = fullSubj, Body = bodyfull }) { smtp.Send(message); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload