1

After running my code, it shows this message:

At most one record can be returned by this subquery.

So, how can I get all the roecords?

Here is my code:

  connection.Open();
            OleDbCommand command1 = new OleDbCommand();
            command1.Connection = connection;
            string cq = "Select Email From student where S_ID=(select S_ID FROM studentbook where DateDiff('d',[Issue_Date], NOW())=31) ";
             command1.CommandText = cq;
             OleDbDataAdapter da1 = new OleDbDataAdapter(command1);
             DataTable dt1 = new DataTable();
             da1.Fill(dt1);
            foreach (DataRow row in dt1.Rows)
            {
                string email = row["Email"].ToString();
                MessageBox.Show("Trying to send email ");

                using (MailMessage mm = new MailMessage("sujitcsecuet@gmail.com", email))
                {
                    mm.Subject = "Attention please,renew your book";
                    mm.Body = string.Format("1 month over,you should renew or return the book");

                    mm.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = "smtp.gmail.com";
                    smtp.EnableSsl = true;
                    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential();
                    credentials.UserName = "abc@gmail.com";
                    credentials.Password = "password";
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials = credentials;
                    smtp.Port = 587;
                    smtp.Send(mm);
                    MessageBox.Show("Email sent successfully");
                }
            }
Kris Vandermotten
  • 10,111
  • 38
  • 49
  • Try with _....where S_ID IN (select ...._ – Steve Aug 29 '15 at 19:18
  • now getting record problem solved but another problem arise and show message"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. " i can not clearly understand the message and what the problem is and what to do? –  Aug 29 '15 at 19:28
  • The message tells you that your connection string lacks a password and a username to access the access DB(Also known as OleDB). https://www.connectionstrings.com/access/ Examples of connection strings with passwords. – misha130 Aug 29 '15 at 19:35
  • Change "S_ID =" to "S_ID IN". This will prevent your sql from crashing if there is more than one row returned – Gregg Aug 29 '15 at 19:43

0 Answers0