I'm trying in c# to simply pull a set of rows from a SQL DB and run through each row I get a result with some code that will email me one time for each row returned.
the below code should work as far as I can tell and returns no errors, I'm stumped. You can assume that the "ConnectionString" is valid and used in plenty of places on the site, and that the query as defined there should definitely return back a row from my DB, as I've verified the exact same line by running it through the raw DB with sql mgmt studio express and I get the results I'm expecting.
all I'm getting though is the single "i got here" email that happens just before I try to enter the loop.
Would really appreciate any insight from smarter people, thanks guys!
string query4 = "SELECT TOP(1)* FROM subscribers WHERE subscriber = 'test'";
string number; string pix; string watcheremail; string watcher;
MailMessage message25 = new MailMessage();
message25.From = new MailAddress("[email protected]");
message25.To.Add(new MailAddress("myemailaddress"));
message25.Body = "i got here";
SmtpClient client25 = new SmtpClient();
client25.Send(message25);
using (SqlConnection connection = new SqlConnection("ConnectionString"))
{
connection.Open();
using (SqlDataAdapter people = new SqlDataAdapter(query4, connection))
{
DataTable people1 = new DataTable();
people.Fill(people1);
foreach (DataRow row in people1.Rows)
{
watcher = row["subscriber"].ToString();
MailMessage message252 = new MailMessage();
message252.From = new MailAddress("[email protected]");
message252.To.Add(new MailAddress("myemailaddress"));
message252.Body = "AND THEN I GOT HERE TOO - " + watcher;
SmtpClient client252 = new SmtpClient();
client252.Send(message252);
}
}
}