Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SqlConnection con1 = new SqlConnection("server=DIPESH-PC\\SQLEXPRESS;uid=sa;pwd=rerf;database=E-REGISTRATION");

C#
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
   {

       SqlCommand cmd1 = new SqlCommand("UPDATE feedback SET ACK=@ACK WHERE EMAIL_ID=@EMAIL_ID", con1);
       if (!string.IsNullOrEmpty(TextBox6.Text))
       {
       cmd1.Parameters.AddWithValue("@ACK",TextBox6.Text);
       }
       con1.Open();
       cmd1.ExecuteNonQuery();
       con1.Close();
       Label1.Text = "  Data Updates Succesfully on  " + System.DateTime.Now.ToShortDateString();
   }


Can somone please tell me why I get the error 'Must declare the scalar variable "@ACK"'.
Posted
Comments
Maciej Los 2-May-14 18:02pm    
Are you shure? What about @EMAIL_ID? You did not specify it.
dipesh_karmakar 2-May-14 18:33pm    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class AboutUs_Objective_AboutUs : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=DIPESH-PC\\SQLEXPRESS;uid=sa;pwd=rerf;database=E-REGISTRATION");
SqlConnection con1 = new SqlConnection("server=DIPESH-PC\\SQLEXPRESS;uid=sa;pwd=rerf;database=E-REGISTRATION");


protected void Page_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from feedback", con);
SqlDataReader reader;
con.Open();
reader = cmd.ExecuteReader();
reader.Read();
TextBox1.Text = reader["EMAIL_ID"].ToString();
TextBox2.Text = reader["FIRST_NAME"].ToString();
TextBox3.Text = reader["MOBILE_NO"].ToString();
TextBox4.Text = reader["SUBJECH"].ToString();
TextBox5.Text = reader["MESSAGE"].ToString();
TextBox6.Text = reader["ACK"].ToString();

reader.Close();

}




protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{

SqlCommand cmd1 = new SqlCommand("UPDATE feedback SET ACK=@ACK WHERE EMAIL_ID=@EMAIL_ID", con1);
cmd1.Parameters.AddWithValue("@EMAIL_ID",TextBox1.Text);
cmd1.Parameters.AddWithValue("@ACK",TextBox6.Text);
con1.Open();
cmd1.ExecuteNonQuery();
con1.Close();
Label1.Text = " Data Updates Succesfully on " + System.DateTime.Now.ToShortDateString();
}

}
dipesh_karmakar 2-May-14 18:39pm    
'Data Updates Succesfully on.........' MESSAGE DISPLAYED SUCCESSFULLY BUT DATABASE DATA FIELD CAN'OT UPDATE.....PLZ HELP ME
Maciej Los 3-May-14 4:10am    
Debug the programm and check what is passed as @ACK and @EMAIL_ID parameter.

1 solution

Get rid of the
VB
if (!string.IsNullOrEmpty(TextBox6.Text))
-- you must have the parameter, if it's NULL you must set it to DBNull.Value
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900