ASP.Net + MSSQL Question

I’m new to Asp.net (though I am experienced in PHP).

Is there a way to select certain rows and for each row, perform a function? Specifically, I want to select specific rows and then send them an email.

Here’s a breakdown:

  1. Select * from STUDENTS where status = active
  2. For each row that is returned, take the $email column and email the student message
  3. Repeat until all qualifying rows have been completed.

Thanks!

Use a foreach loop. :slight_smile:
http://msdn.microsoft.com/en-us/library/ttw7t8t6(VS.80).aspx

Well, that depends on how you going to do the query.

  1. Use “select columname1, columnname2 from students where status = 1”

if you are selecting this with a data reader you can do it within the reader:


SqlCommand selectCmd = new SqlCommand("select string here",connection)
SqlDataReader reader = selectCmd.ExecuteReader();
while (reader.Read())
{
string useremail = reader["MemberEmailColumnName'].ToString();
//SEND EMAIL HERE
}

Thank you both!

I think I can figure it out form here.

To imaginekitty, I swear I search for the ‘foreach’ option and couldn’t find it! :lol:

NightStalker-DNS, thank you for the example!!