title: Insert SQL statement is not working after checking against quantities from tables in database
body: <p>I created a sale table which Insert function does not work properly. It shows the error message </p>
  
  <blockquote>
    <p>Must declare the scalar variable "@iProductID"</p>
  </blockquote>
  
  <p>at the statement </p>
  
  <pre><code>using (var sdRead = cmdOrder.ExecuteReader())
  </code></pre>
  
  <p>I am really stuck here. I also want to know how I can achieve for inserting <code>SaleID</code> with auto-increment without with any input field at the form. Every time I insert a new record, <code>SaleID</code> should be auto-generated and saved in the database. </p>
  
  <p>My code below work like this. I checked available stocks from my <code>Product</code> table. If quantity order is greater than quantity from <code>Product</code> table, show error message. </p>
  
  <p>Otherwise, proceed to inserting order information into <code>Sale</code> table. Any help is appreciated.</p>
  
  <pre><code>private void btnOrder_Click(object sender, EventArgs e)
  {
          int iQuantityDB;
          int iCustomerID = Convert.ToInt32(txtCustomerID.Text);
          int iProductID = Convert.ToInt32(txtProductID.Text);
          decimal dPrice = Convert.ToDecimal(txtPrice.Text);
          int iQuantity = Convert.ToInt32(txtQuantity.Text);
          decimal dSubtotal = Convert.ToDecimal(txtSubTotal.Text);
          decimal dGST = Convert.ToDecimal(txtGST.Text);
          decimal dTotal = Convert.ToDecimal(txtTotal.Text);
  
          string strConnectionString = @"Data Source = KK\SQLEXPRESS; Integrated Security = SSPI; Initial Catalog = JeanDB; MultipleActiveResultSets=True;";
          using (var sqlconn = new SqlConnection(strConnectionString))
          {
              sqlconn.Open();
              string querySelectQuantity = @"Select Quantity from dbo.JeanProduct WHERE ProductID = @iProductID";
              using (var cmdOrder = new SqlCommand(querySelectQuantity, sqlconn))
              {
                  using (var sdRead = cmdOrder.ExecuteReader())
                  {
                      sdRead.Read();
                      iQuantityDB = Convert.ToInt32(sdRead["Quantity"]);
                  }
              }
  
              if (iQuantityDB &gt; iQuantity)
              {
                  string InsertQuery = @"INSERT INTO Sale(CustomerID, ProductID, Price, Quantity, Subtotal, GST, Total)VALUES(@iCustomerID, @iProductID, @dPrice, @iQuantity, @dSubtotal, @dGST, @Total)";
                  using (var InsertCMD = new SqlCommand(InsertQuery, sqlconn))
                  {
                      InsertCMD.Connection = sqlconn;
  
                      InsertCMD.Parameters.AddWithValue("@iCustomerID", iCustomerID);
                      InsertCMD.Parameters.AddWithValue("@iProdcutID", iProductID);
                      InsertCMD.Parameters.AddWithValue("@dPrice", dPrice);
                      InsertCMD.Parameters.AddWithValue("@iQuantity", iQuantity);
                      InsertCMD.Parameters.AddWithValue("@dSubtotal", dSubtotal);
                      InsertCMD.Parameters.AddWithValue("@dGST", dGST);
                      InsertCMD.Parameters.AddWithValue("@dTotal", dTotal);
                      InsertCMD.ExecuteNonQuery();
  
                      LoadDataonTable();
                  }
              }
              else
              {
                  MessageBox.Show("no more stock");
  
              }
              sqlconn.Close();
          }
  }
  </code></pre>