How to update the value of 'IsSent' column after sending an email?
<p>I am developing a web application that provides the users with short quizzes. The system will check the Quiz table in the database which consists of a QuizID and IsSent column.</p>

<p>If the IsSent column (which is a bit data type) has a value of 0 (which is false), the system will send the quiz to all users. If it has a 1, this means the quiz has already been sent.</p>

<p>I am able to let the application sends emails, but now I want the system to update the value of IsSent to 1 or true after sending the email but I don't know how to do it.</p>

<p>Can anyone tell me how to do it?</p>

<p>My Code:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    SendEmailTOAllUser();
}


protected void SendEmail(string toAddress, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml) 
{
    SmtpClient sc = new SmtpClient("SMTP (MAIL) ADDRESS");
    try
    {
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("pssp@gmail.com", "OUR SYSTEM");
        msg.To.Add(toAddress);
        msg.Subject = MailSubject;
        msg.Body = MessageBody;
        msg.IsBodyHtml = isBodyHtml;
        //Response.Write(msg);
        sc.Send(msg);
    }
    catch (Exception ex)
    {
        throw ex;
    }

}

protected void SendEmailTOAllUser()
{
    string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspTest;Integrated Security=True";
    string cmdText = "SELECT QuizID, IsSent FROM dbo.QUIZ";
    string cmdText2 = "SELECT Username FROM dbo.employee";

    Collection&lt;string&gt; emailAddresses = new Collection&lt;string&gt;();
    string link = "";
    string body = "";

    using (SqlConnection conn = new SqlConnection(connString))
    {
        conn.Open();
        // Open DB connection.
        using (SqlCommand cmd = new SqlCommand(cmdText, conn))
        {
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader != null)
            {
                while (reader.Read())
                {
                    if (!(bool)reader["IsSent"])
                    {
                        string quizid = reader["QuizID"].ToString();
                        link = "&lt;a href='http://pmv/pssp/StartQuiz.aspx?testid=" + quizid + "'&gt; Click here to participate &lt;/a&gt;";
                        body = @"&lt;b&gt; Please try to participate in the new short safety quiz &lt;/b&gt;"
                                            + link +
                                            @"&lt;br /&gt; &lt;br /&gt;
                        This email was generated using the &lt;a href='http://pmv/pssp/Default.aspx'&gt;PMOD Safety Services Portal &lt;/a&gt;. 
                        Please do not reply to this email.
                        ";    
                    }
                }
            }
            reader.Close();
        }

        using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
        {
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader != null)
            {
                while (reader.Read())
                {
                    string emailTo = reader["Username"].ToString();
                    string receiverEmail = emailTo + "@gmail.com";
                    emailAddresses.Add(receiverEmail);
                }
            }
            reader.Close();
        }
        conn.Close();
    }

    foreach (string email in emailAddresses)
    {
        SendEmail(email, "", "Notification Email Subject", body, true);
    }
}
</code></pre>
