Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am getting an error with below code the message that i am getting it is:


C#
Server Error in '/' Application.

Must declare the scalar variable "@uuu". 
  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 "@uuu".

Source Error: 



Line 43:                 SqlCommand passcom = new SqlCommand(checkpasswordquery, adminlog);
Line 44:                 cmd.Parameters.AddWithValue("@uuu", adminusernmetxtbx.Text);
Line 45:                 string password = passcom.ExecuteScalar().ToString().Replace(" ", "");
Line 46: 
Line 47: 



C#
protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection adminlog = new SqlConnection(sc);
            adminlog.Open();
            string checkuser = "Select count(*) from UserInfo where UID=@uuu";
            SqlCommand cmd = new SqlCommand(checkuser, adminlog);
            cmd.Parameters.AddWithValue("@uuu",adminusernmetxtbx.Text);
            int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());


            adminlog.Close();



            if (temp == 1)
            {
                adminlog.Open();
                string checkpasswordquery = "Select count(*) from UserInfo where UID=@uuu";
                SqlCommand passcom = new SqlCommand(checkpasswordquery, adminlog);
                cmd.Parameters.AddWithValue("@uuu", adminusernmetxtbx.Text);
                string password = passcom.ExecuteScalar().ToString().Replace(" ", "");


                if (password == adminpasstxtbx.Text)
                {
                    Session["UsrNme"] = adminusernmetxtbx.Text;
                    Response.Redirect("BeravaAdmin.aspx");
                }

                else
                {
                    adminpasstxtbx.Text = "Password is incorrect";
                }
            }
Posted
Comments
[no name] 19-Jul-14 19:55pm    
passcom.Parameters.AddWithValue("@uuu", adminusernmetxtbx.Text);

1 solution

As Wes pointed out, you declare a second SqlCommand object named passcom but you then add the parameter to the cmd object not the passcom one.
 
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