Sunday, March 11, 2012

email error

the site i am working on iswww.papertrailinvites.com

on the left when you enter your email address and hit submit i get this error:

Server Error in '/' Application.

Must declare the scalar variable "@.Email".

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: Must declare the scalar variable "@.Email".

Source Error:

Line 29: Line 30: conn.Open();Line 31: cmd.ExecuteNonQuery();Line 32: Line 33: }

My code is below:

protected void Button1_Click(object sender, EventArgs e) {using (SqlConnection conn =new SqlConnection(ConfigurationManager.ConnectionStrings["cardsConnectionString1"].ConnectionString)) {string email = Newsletter_Email.Text; SqlCommand cmd =new SqlCommand("INSERT INTO Email (EmailAddress) Values (@.Email)", conn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@.Name", email); conn.Open(); cmd.ExecuteNonQuery(); } }

it looks like you mixed up "name" and "email"

try this:

protected void Button1_Click(object sender, EventArgs e) {using (SqlConnection conn =new SqlConnection(ConfigurationManager.ConnectionStrings["cardsConnectionString1"].ConnectionString)) {string email = Newsletter_Email.Text; SqlCommand cmd =new SqlCommand("INSERT INTO Email (EmailAddress) Values (@.Email)", conn); cmd.CommandType = CommandType.Text;//re-name param to match the cmd statement cmd.Parameters.AddWithValue("@.Email", email); conn.Open(); cmd.ExecuteNonQuery(); } }

|||

gers my code and i still get the error...

protectedvoid Button1_Click(object sender,EventArgs e)

{

using (SqlConnection conn =newSqlConnection(ConfigurationManager.ConnectionStrings["cardsConnectionString1"].ConnectionString)) {String newemail = Newsletter_Email.Text;

SqlCommand cmd =newSqlCommand("INSERT INTO Email (EmailAddress) Values (@.EmailAddress)", conn);

cmd.CommandType =

CommandType.Text;

cmd.Parameters.AddWithValue(

"@.EmailAdress", newemail);

conn.Open();

cmd.ExecuteNonQuery();

}

|||

double check your spelling.

your sql says: @.EmailAddress

your param says: @.EmailAdress

No comments:

Post a Comment