title: Must declare the scalar variable "@lblCmpUserName"
body: <p>When a user logs in with his <code>UserName</code>, I send the <code>UserName</code> to the next page as below code in <code>Page_Load</code></p>
  
  <pre><code> lblCmpUserName.Text = Server.UrlDecode(Request.QueryString["Parameter"].ToString());
  </code></pre>
  
  <p>and then I want to store the "Company details" with the UserName in a SQL Server 2008 table.</p>
  
  <p>I got the error </p>
  
  <blockquote>
    <p>Must declare the scalar variable "@lblCmpUserName"</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>    protected void BtnCmpApproval_Click(object sender, EventArgs e)
      {
         SqlConnection SqlCon = new SqlConnection(GetConnectionString());
         string query = "INSERT INTO Company_Info2 VALUES (@lblCmpUserName, @txtCmpName,  @txtRegCountry, @txtCmpRegNo, @txtCmpEstdate,@AFU1, @txtCmpAddress, @ddlAddrIn)";
         try
         {
            SqlCon.Open();
  
            SqlCommand cmd = new SqlCommand(query, SqlCon);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@UserName", lblCmpUserName.Text);
            cmd.Parameters.AddWithValue("@Cmp_Name", txtCmpName.Text);
            cmd.Parameters.AddWithValue("@Commercial_RegNo", txtRegCountry.Text);
            cmd.Parameters.AddWithValue("@Comm_Country", txtCmpRegNo.Text);
            cmd.Parameters.AddWithValue("@Cmp_EstablishDate", txtCmpEstdate.Text);
            cmd.Parameters.AddWithValue("@Cmp_DocPath", AFU1.FileName);
            cmd.Parameters.AddWithValue("@txtCmpAddress", txtCmpAddress.Text);
            cmd.Parameters.AddWithValue("@ddlAddrIn", ddlAddrIn.SelectedItem.Text);
  
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
           throw new Exception(ex.Message);
        }
        finally
        { 
           SqlCon.Close();
        }
      } 
  </code></pre>