Domanda

I'm building for my project work at school a website. The main idea is that users can report damage or report a non functioning computer. Then the IT department can give in if they've taken any steps try fixing it and there is also a checkbox if the problem is dealth with. If the checkbox in the formview is checked and updated, there should be sent an automatic e-mail to the original user with a message that the problem is solved. I've done everything and everything works, except for the e-mail part. Can anybody give me some advice in how I should do this? There is an unique datasource who handeles the update statement.

Yours sincerely; A.

Here is my code:

<asp:AccessDataSource ID="accAfgehandeld" runat="server" 
    DataFile="~/App_data/dbMeldingen.mdb" 
    DeleteCommand="DELETE FROM [tblMeldingen] WHERE [MeldingID] = ?" 
    InsertCommand="INSERT INTO [tblMeldingen] ([MeldingID], [Afgehandeld], [Categorie]) VALUES (?, ?, ?)" 
    SelectCommand="SELECT [MeldingID], [Afgehandeld], [Categorie] FROM [tblMeldingen] WHERE ([MeldingID] = ?)" 
    UpdateCommand="UPDATE [tblMeldingen] SET [Afgehandeld] = true, [Categorie] = ? WHERE [MeldingID] = ?"
    OnUpdated="OnDSUpdatedHandler">
    <DeleteParameters>
        <asp:Parameter Name="MeldingID" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="MeldingID" Type="Int32" />
        <asp:Parameter Name="Afgehandeld" Type="Boolean" />
        <asp:Parameter Name="Categorie" Type="Int32" />
    </InsertParameters>
    <SelectParameters>
        <asp:QueryStringParameter Name="MeldingID" QueryStringField="id" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>

        <asp:Parameter Name="Categorie" Type="Int32" />
        <asp:Parameter Name="MeldingID" Type="Int32" />
    </UpdateParameters>
</asp:AccessDataSource>

and my script in the same page:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="meldingendetails.ascx.vb" Inherits="meldingendetails" %>

<script runat="server">
private void OnDSUpdatedHandler(Object sender, e.Updated) {

   if (e.AffectedRows > 0) 
    {
       MailMessage mailMessage = new MailMessage();
       SmtpClient smtpClient = new SmtpClient("smtp.your-isp.com");
       smtpClient.Send(mailMessage);  
   } 
}
</script>

Visual studio gives an error over and over again with my script, even from the void part...

È stato utile?

Soluzione

Set OnUpdated-handler

<asp:SqlDataSource
     ...
      UpdateCommand="..."
      OnUpdated="OnDSUpdatedHandler">
  </asp:SqlDataSource>

and use it to send email

<script runat="server">
private void OnDSUpdatedHandler(Object source, SqlDataSourceStatusEventArgs e) {

   if (e.AffectedRows > 0) {
       MailMessage mailMessage = new MailMessage();
       ...
       SmtpClient smtpClient = new SmtpClient("smtp.your-isp.com");
       smtpClient.Send(mailMessage);  
   } 

}
</script>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top