I don't know if I am able to exactly explain my question but best of information that I am able to provide is following:
I have a datagrid view list of emails in it, I want to send emails to this list one by one and on the basis of the email (which is also a primary key), some information is fetched from the database and that fetched values should be replaced in my email body on specific places which are marked. It works perfectly when I enter all value manually but once I try to get values from the data grid view the values are displayed in the text fields (after getting fetched from the database) but when the email is sent, the required values are not replaced with the marked tags in my email body, as per my code tweaks, I have come to a conclusion that the value that I receive in the textbox from the database is dealt as a null value when passed to my email body. Here is my value passing code:
int cellValue = 0;
int rowCount = dgvStudents.Rows.Count;
for (int i = 0; i <= rowCount; i++)
{
string id = dgvStudents.Rows[i].Cells[cellValue].Value.ToString();
string campus = dgvStudents.Rows[i].Cells[cellValue + 1].Value.ToString();
txtStudentId.Text = id;
cmbStudyCenter.Text = campus;
}
**//And this is where the values are replaced with my marked tags:**
if (rdPreFinal.Checked)
{
string txtPreFinalText = txtEmailTemplate.Text.Replace("[ENTER VIVA TYPE HERE]", rdPreFinal.Text);
txtEmailTemplate.Text = txtPreFinalText;
}
else if (rdFinal.Checked)
{
string rdFinalText = txtEmailTemplate.Text.Replace("[ENTER VIVA TYPE HERE]", rdFinal.Text);
txtEmailTemplate.Text = rdFinalText;
}
else if (rdTestPhase.Checked)
{
string rdTestPhaseText = txtEmailTemplate.Text.Replace("[ENTER VIVA TYPE HERE]", rdTestPhase.Text);
txtEmailTemplate.Text = rdTestPhaseText;
}
string newDateTime = VivaDate.Text + " " + timeFormat.Text;
string newId = txtEmailTemplate.Text.Replace("[ENTER STUDENT ID]", txtStudentId.Text);
txtEmailTemplate.Text = newId;
string groupId = txtEmailTemplate.Text.Replace("[ENTER GROUP ID]", txtGroupId.Text);
txtEmailTemplate.Text = groupId;
string newDate = txtEmailTemplate.Text.Replace("[VIVA DATE/TIME]", newDateTime);
txtEmailTemplate.Text = newDate;
string newVivaStation = txtEmailTemplate.Text.Replace("[ENTER VIVA STATION DETAIL HERE ALONFWITH COMPLETE ADDRESS]", txtVivaStation.Text);
txtEmailTemplate.Text = newVivaStation;
//fetching previouus date and time for the viva
SqlConnection Connection = new SqlConnection(connectionString);
string commandText = "Select * from Sent_Viva_Emails where Student_Id ='" + txtStudentId.Text + "'";
SqlCommand Command = new SqlCommand(commandText, Connection);
Connection.Open();
SqlDataReader sdr1 = Command.ExecuteReader(); SqlConnection sql = new SqlConnection();
if (sdr1.Read())
{
string PreviousDate = sdr1.GetValue(6).ToString();
string PreviousTime = sdr1.GetValue(7).ToString();
PreviousDate = txtEmailTemplate.Text.Replace("[ENTER PREVIOUS VIVA DATE]", PreviousDate);
txtEmailTemplate.Text = PreviousDate;
PreviousTime = txtEmailTemplate.Text.Replace("[ENTER PREVIOUS VIVA TIME]", PreviousTime);
txtEmailTemplate.Text = PreviousTime;
}
I have searched StackOverflow and some other online platforms but could not get what I want. I hope I was able to explain my problem or experts can suggest me more changes to my questions to make it more understandable to answer. Thank you :)
Simplified version of my question:
string newVivaStation = txtEmailTemplate.Text.Replace("[ENTER VIVA STATION DETAIL HERE ALONFWITH COMPLETE ADDRESS]", txtVivaStation.Text);
txtEmailTemplate.Text = newVivaStation;
on placing break points, I see value is passing through txtVivaStation.txtbut it never replaces in
[ENTER VIVA STATION DETAIL HERE ALONFWITH COMPLETE ADDRESS]
my email body. value from txtVivaStation.txt should be replaced with [ENTER VIVA STATION DETAIL HERE ALONFWITH COMPLETE ADDRESS] in my email body. Here is SS of my result image after values are replaced
As you can see only date was replaced correctly with my marked tag but all other values were blank.
One Liner: value that are coming dynamically from the datagrid view to my textfields are not working but if I select enter values manually, it works fine.