I'm a new comer to ASP.Internet, and i'm trying to produce a contact page which transmits an e-mail at submission too storing the information inside a database.

I've read numerous lessons, and i'm pretty confident with a fundamental contact page to email setup - however i am getting challenge with the database some of it.

Please tell me if you've ever carried this out, or maybe you can provide any information that will assist me with this particular task.

I'm running ASP.Internet 2.

Thanks ahead of time.

I am very a new comer to both C# and ASP.Internet (newbie IT student). Up to last month, I'd never even seen C# code, a smaller amount designed anything in C#. I, too, happen to be brushing the web for any fix for your problem. Following a week of trying out some code, I finally figured it. The below code will help you to create an ASP.Internet "E Mail UsInch email form, and can send the data within the form to some SQL Server database. I really hope this can help anyone to steer clear of the same aggravation I experienced! (If anybody knows a method to program this more effectively, I'd like to hear your ideas.)

This Is Actually The CODE For That ASPX.CS FILE Connected To The FORM:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Contact : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)


//Code for the Reset event (will reset form data):

protected void Reset(object s, EventArgs e)
    fname.Text = "";
    lname.Text = "";
    email.Text = "";
    phone.Text = "";
    comments.Text = "";

//Code for the SendMail Event; will send email and write info in email into database:

protected void SendMail(object sender, EventArgs e)
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(email.Text);
    mail.Subject = "Contact Us";
    mail.IsBodyHtml = true;
    mail.Body += "First Name: " + fname.Text + "<br />";
    mail.Body += "Last Name: " + lname.Text + "<br />";
    mail.Body += "Comments: " + comments.Text + "<br />";
    mail.Body += "Phone Number: " + phone.Text + "<br />";

    SmtpClient smtp = new SmtpClient();
    smtp.Host = "NAME OF SMTP RELAY SERVER";

protected void insertInfo(object sender, EventArgs e)
    SqlConnection myConnection = new SqlConnection             (ConfigurationManager.ConnectionStrings["WEB.CONFIG CONNECTION STRING NAME"].ToString());

    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
    cmd.CommandType = System.Data.CommandType.Text;
    cmd.CommandText = "INSERT INTO TABLE NAME (fname, lname, email, phone, comment)    
VALUES (@fname, @lname, @email, @phone, @comments)";
    cmd.Connection = myConnection;

    cmd.Parameters.Add("@fname", fname.Text);
    cmd.Parameters.Add("@lname", lname.Text);
    cmd.Parameters.Add("@email", email.Text);
    cmd.Parameters.Add("@phone", phone.Text);
    cmd.Parameters.Add("@comments", comments.Text);