locked
Using C# to send form Data to Access DB. RRS feed

  • Question

  • User552461174 posted

    Hi All, new to this forum, really hope someone can help me out. 

    I have a website that I have created a Form on.  I have built the form with HTML (tables) and ASP.net controls (asp textboxes).  I have a c# codebehind file that processes the form.  It sends the form data to my email box. 

    I would like to also send the form data into a Database at the same time.   Is it possible to do this with C# code added to the codebehind file so the "OnClick" the script does both actions for me? 

    Current C# Script:

    using System;
    using System.Net;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net.Mail;

    public partial class Contact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
       
        }
    protected void SendMail(object sender, EventArgs e)
        {
            if (!IsValid)
            {
                return;
                }
                else
                {
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(EmailTB.Text);
            mail.To.Add("xxx@yyyt.com");
            mail.Subject = "ProAdInsight Contact Form";
            mail.IsBodyHtml = true;
            mail.Body += "First Name: " + FnameTB.Text + "<br />";  
            mail.Body += "Last Name: " + LnameTB.Text + "<br />";  
            mail.Body += "Email: " + EmailTB.Text + "<br />";  
            mail.Body += "Phone: " + PhoneTB.Text + "<br />";
            mail.Body += "Services Needed: " + Svcs.Text + "<br />";
            mail.Body += "Source? " + Source.Text + "<br />";
            mail.Body += "Comments: " + CommentsTB.Text + "<br />";
            MailAddress copy = new MailAddress ("bbb@q.com");
            mail.CC.Add(copy);
      

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "localhost";
            smtp.Send(mail);
            FormPH.Visible = false;
            Response.Redirect("http://proadinsight.com/Thankyou.aspx");
                }    
    }
    protected void Reset(object s, EventArgs e)
        {
            FnameTB.Text = "";
            LnameTB.Text = "";
            EmailTB.Text = "";
            PhoneTB.Text = ""; 
            Svcs.Text = "";
            Source.Text = "";
            CommentsTB.Text = "";      

     

    If someone could provide me with some guidance here, (or the code itself, as I am sure it is not that difficult to do this for a programmer) I would be greatly appreciative. 

     

    Chad

    Thursday, July 29, 2010 3:23 PM

Answers

All replies