title: Inserting Parameters, C#, T-Sql
body: <p>I am trying to insert a parameter through an aspx page via text box. I set my parameters up, but evertime I executenonquery, the @Username shows up in the database instead of the actual value.
  Below is my code. Can anyone shed a little insight?</p>
  
  <p>This is the full code:</p>
  
  <pre><code>protected void btn_SubmitUserInfo_Click(object sender, EventArgs e)
      {
          SqlConnection conn = new SqlConnection();
          conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=c:\\Documents and Settings\\xm\\My Documents\\Visual Studio 2010\\Projects\\CreateUser\\CreateUser\\App_Data\\UserInformation.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True; Integrated Security=SSPI");
  
          //Open the connection outside of the try statement
          conn.Open();
  
          try
          {
              //Create a command for the stored procedure and tie it into the connection
              SqlCommand cmd = new SqlCommand("InsertUserValues", conn);
  
              //Set the command type so it know to execute the stored proc
              cmd.CommandType = CommandType.StoredProcedure;
  
              //Declare Parameters
  
  
              SqlParameter @UserID = new SqlParameter("@UserID", System.Data.SqlDbType.Int);
              @UserID.Direction = ParameterDirection.Input;
              @UserID.Value = txtUserID.Text;
  
  
              SqlParameter @UserName = new SqlParameter("@UserName", System.Data.SqlDbType.VarChar);
              @UserName.Direction = ParameterDirection.Input;
              @UserName.Value = txtUserName.Text;
  
              SqlParameter @UserPassword = new SqlParameter("@UserPassword", System.Data.SqlDbType.VarChar);
              @UserPassword.Direction = ParameterDirection.Input;
              @UserPassword.Value = txtPassword.Text;
  
              SqlParameter @FirstName = new SqlParameter("@FirstName", System.Data.SqlDbType.VarChar);
              @FirstName.Direction = ParameterDirection.Input;
              @FirstName.Value = txtFirstName.Text;
  
              SqlParameter @LastName = new SqlParameter("@LastName", System.Data.SqlDbType.VarChar);
              @LastName.Direction = ParameterDirection.Input;
              @LastName.Value = txtLastName.Text;
  
              SqlParameter @Address = new SqlParameter("@Address", System.Data.SqlDbType.VarChar);
              @Address.Direction = ParameterDirection.Input;
              @Address.Value = txtAddress.Text;
  
              SqlParameter @AptNum = new SqlParameter("@AptNum", System.Data.SqlDbType.VarChar);
              @AptNum.Direction = ParameterDirection.Input;
              @AptNum.Value = txtAptNumber.Text;
  
              SqlParameter @City = new SqlParameter("@City", System.Data.SqlDbType.VarChar);
              @City.Direction = ParameterDirection.Input;
              @City.Value = txtCity.Text;
  
              SqlParameter @State = new SqlParameter("@State", System.Data.SqlDbType.VarChar);
              @State.Direction = ParameterDirection.Input;
              @State.Value = txtState.Text;
  
              //SqlParameter @Zip = new SqlParameter("@Zip", System.Data.SqlDbType.Int);
              //@Zip.Direction = ParameterDirection.Input;
              //@Zip.Value = Convert.ToInt32(txtZip.Text);
  
              //add new parameter command to object
              cmd.Parameters.Add(@UserID);
              cmd.Parameters.Add(@UserName);
              cmd.Parameters.Add(@UserPassword);
              cmd.Parameters.Add(@FirstName);
              cmd.Parameters.Add(@LastName);
              cmd.Parameters.Add(@Address);
              cmd.Parameters.Add(@AptNum);
              cmd.Parameters.Add(@City);
              cmd.Parameters.Add(@State);
              //cmd.Parameters.Add(@Zip);
  
              //execute nonquery
              cmd.ExecuteNonQuery();
  
          }
          finally
          {
              lblSucess.Text = "Your information has been submitted";
              //Close the connection
              if (conn != null)
              {
                  conn.Close();
              }
          }
  </code></pre>
  
  <p>This is the stored Procedure:</p>
  
  <pre><code>ALTER PROCEDURE dbo.InsertUserValues
  
  @UserID int,
  @UserName varchar(50),
  @UserPassword varchar(100),
  @FirstName varchar(50),
  @LastName varchar(50),
  @Address varchar(50),
  @AptNum varchar(50),
  @City varchar(50),
  @State varchar(50)
  
  
  AS
  INSERT INTO tb_User( user_Name, password, f_Name, l_Name, address, apt_Number, city, state)
  VALUES (                '@UserName', '@UserPassword', '@FirstName', '@LastName', '@Address', '@AptNum', '@City', '@State')
  </code></pre>