title: Defining SQL parameters for INSERT Statement in C#
body: <p>I have created a parameterized SQL insert query and I have made a mistake somewhere. I kept getting a message that values would be truncated, so, during troubleshooting I reduced the query to only fields that required values (NULLs not allowed), and the insert statement completed.  </p>
  
  <p>I check the table, and I see my parameter names inserted, not the values they should be pulling from the form's textboxes. </p>
  
  <p>Obviously I am calling my parameters incorrectly but I just can't figure out where I have gone wrong. I am hoping you all can help me. </p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>NOTE:</strong> Yes, I know there are more parameters than what I am using in the <code>INSERT</code> string.  I have intentionally cut down the values used for troubleshooting. </p>
  
  <p>Thanks again!</p>
  
  <pre><code>try {
      string InsertString = @"INSERT INTO Item.Itemtable
          (ItemNumber, ItemDesc, RatioToOriginalItemNumber, OriginalItemNumber, EntreeCount, ItemType, ProteinBeverage)
          Values(@ItemNumberValue, '@ItemDescValue', @RatioToOriginalItemNumberValue, @OriginalItemNumberValue, @EntreeCountValue, '@ItemTypeValue', @ProteinBeverageValue)";
      SqlCommand InsertNewItem = new SqlCommand(InsertString, PmixWriter);
      //Define Insert Parameters
      SqlParameter @ItemNumberValue = InsertNewItem.Parameters.Add("@ItemNumberValue", System.Data.SqlDbType.Int);
      SqlParameter @ItemDescValue = InsertNewItem.Parameters.Add("@ItemDescValue", System.Data.SqlDbType.VarChar, 100);
      SqlParameter @ItemTypeValue = InsertNewItem.Parameters.Add("@ItemTypeValue", System.Data.SqlDbType.VarChar, 100);
      SqlParameter @ProteinBeverageValue = InsertNewItem.Parameters.Add("@ProteinBeverageValue", System.Data.SqlDbType.VarChar, 100);
      SqlParameter @IsCouponValue = InsertNewItem.Parameters.Add("@IsCouponValue", System.Data.SqlDbType.Char, 3);
      SqlParameter @EntreeCountValue = InsertNewItem.Parameters.Add("@EntreeCountValue", System.Data.SqlDbType.Real);
      SqlParameter @BevCountValue = InsertNewItem.Parameters.Add("@BevCountValue", System.Data.SqlDbType.TinyInt);
      SqlParameter @OriginalItemNumberValue = InsertNewItem.Parameters.Add("@OriginalItemNumberValue", System.Data.SqlDbType.Int);
      SqlParameter @RatioToOriginalItemNumberValue = InsertNewItem.Parameters.Add("@RatioToOriginalItemNumberValue", System.Data.SqlDbType.TinyInt);
      SqlParameter @FPBeverageCountValue = InsertNewItem.Parameters.Add("@FPBeverageCountValue", System.Data.SqlDbType.Int);
      SqlParameter @FPBeverageEntreeCountValue = InsertNewItem.Parameters.Add("@FPBeverageEntreeCountValue", System.Data.SqlDbType.Int);
      SqlParameter @FoodCostValue = InsertNewItem.Parameters.Add("@FoodCostValue", System.Data.SqlDbType.Money);
  
      //Assign and covert values to the stated SQL parameters.
      @ItemNumberValue.Value = Convert.ToInt32(ItemNumberBox.Text);
      @ItemDescValue.Value = ItemDescBox.Text;
      @ItemTypeValue.Value = ItemTypeBox.Text;
      @ProteinBeverageValue.Value = ProteinBevBox.Text;
      @IsCouponValue.Value = IsCouponBox.Text;
      @EntreeCountValue.Value = Convert.ToInt32(EntreeCountBox.Text);
      @BevCountValue.Value = Convert.ToInt32(BevCountBox.Text);
      @OriginalItemNumberValue.Value = Convert.ToInt32(OriginalItemNumBox.Text);
      @RatioToOriginalItemNumberValue.Value = Convert.ToInt32(RatioBox.Text);
      @FPBeverageCountValue.Value = Convert.ToInt32(FPBevBox.Text);
      @FPBeverageEntreeCountValue.Value = Convert.ToInt32(FPBevEntreeBox.Text);
      @FoodCostValue.Value = Convert.ToDecimal(0.00);
  
      InsertNewItem.ExecuteNonQuery();
  } catch (SqlException) {
      throw;   
  }
  </code></pre>