citizenzen
Programmer
I have tried everything and I can't get the data to loop in my email. I am only getting one record, where I should get several per record.
I took out the variables in the while loop and declared those. i tried
===================CODE=========================
protected void RejTapeBut_Click(object sender, EventArgs e)
//begin mailer class for rejection
MailAddress From = new MailAddress("Email Address here", "Display Name");
MailAddress To = new MailAddress("email address here", "User's name");
MailMessage rejectMail = new MailMessage(From, To);
rejectMail.Subject = "Rejected Tape Request";
//rejectMail.Body = txtBody.Text.Trim();
//Begin rejection Email
string rejEmailStr = ConfigurationManager.ConnectionStrings["tapelibraryconn"].ConnectionString;
SqlConnection rejConn = new SqlConnection(rejEmailStr);
try
{
rejConn.Open();
SqlCommand rejTapeComm = new SqlCommand("select * from view_showTapeReqsDetails WHERE TapeReqID=" + TapeRequestsGrid.SelectedValue, rejConn);
SqlDataReader rejReader = rejTapeComm.ExecuteReader();
//variables in email
string User;
int myRequest;
string Email;
string Number ;
string Show ;
string Barcode ;
do
//while (rejReader.Read())
while (rejReader.Read())
{
User = (string)rejReader["User"];
myRequest = (int)rejReader["TapeReqID"];
Email = (string)rejReader["UserEmail"];
Number = (string)rejReader["Number"];
Show = (string)rejReader["ShowTitle"];
Barcode = (string)rejReader["Barcode"];
rejectMail.Body = "Rejected Request #:" + myRequest + "<br>" + Show + "<br>Barcode:" + Barcode + "<br>Number:" + Number;
}
while (rejReader.NextResult());
rejectMail.IsBodyHtml = true;
SmtpClient rejectClient = new SmtpClient("IP #");
rejectClient.Send(rejectMail);
TapeReqsLbl.Text = "Email Sent Successfully";
rejReader.Close();
}
catch (SqlException ex)
{
TapeReqsLbl.Text= "Database Error Occured while sending: <br>" + ex.ToString();
}
catch (Exception ex)
{
TapeReqsLbl.Text = "General Error Occured while sending: <br>" + ex.ToString();
}
finally
{
rejConn.Close();
}
}
=============================================
I took out the variables in the while loop and declared those. i tried
===================CODE=========================
protected void RejTapeBut_Click(object sender, EventArgs e)
//begin mailer class for rejection
MailAddress From = new MailAddress("Email Address here", "Display Name");
MailAddress To = new MailAddress("email address here", "User's name");
MailMessage rejectMail = new MailMessage(From, To);
rejectMail.Subject = "Rejected Tape Request";
//rejectMail.Body = txtBody.Text.Trim();
//Begin rejection Email
string rejEmailStr = ConfigurationManager.ConnectionStrings["tapelibraryconn"].ConnectionString;
SqlConnection rejConn = new SqlConnection(rejEmailStr);
try
{
rejConn.Open();
SqlCommand rejTapeComm = new SqlCommand("select * from view_showTapeReqsDetails WHERE TapeReqID=" + TapeRequestsGrid.SelectedValue, rejConn);
SqlDataReader rejReader = rejTapeComm.ExecuteReader();
//variables in email
string User;
int myRequest;
string Email;
string Number ;
string Show ;
string Barcode ;
do
//while (rejReader.Read())
while (rejReader.Read())
{
User = (string)rejReader["User"];
myRequest = (int)rejReader["TapeReqID"];
Email = (string)rejReader["UserEmail"];
Number = (string)rejReader["Number"];
Show = (string)rejReader["ShowTitle"];
Barcode = (string)rejReader["Barcode"];
rejectMail.Body = "Rejected Request #:" + myRequest + "<br>" + Show + "<br>Barcode:" + Barcode + "<br>Number:" + Number;
}
while (rejReader.NextResult());
rejectMail.IsBodyHtml = true;
SmtpClient rejectClient = new SmtpClient("IP #");
rejectClient.Send(rejectMail);
TapeReqsLbl.Text = "Email Sent Successfully";
rejReader.Close();
}
catch (SqlException ex)
{
TapeReqsLbl.Text= "Database Error Occured while sending: <br>" + ex.ToString();
}
catch (Exception ex)
{
TapeReqsLbl.Text = "General Error Occured while sending: <br>" + ex.ToString();
}
finally
{
rejConn.Close();
}
}
=============================================