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");
}
}