title: SQL ExecuteNonQuery throws "Incorrect syntax near '0'."
body: <p>I have the following code that I am using to insert a number of rows into a database:</p>
  
  <pre><code>   _conn.Open();
     SqlCommand command = new SqlCommand(_insert[0].ToString(), _conn);
     command.Parameters.AddRange((_insert[1] as List&lt;SqlParameter&gt;).ToArray());
     Int32 rowsAffected = command.ExecuteNonQuery();
     _conn.Close();
  </code></pre>
  
  <p>The command (_insert[1].ToString()) is:</p>
  
  <pre><code>"INSERT INTO Candidate (id, name) VALUES ({0},{1}),({2},{3}),({4},{5}),({6},{7}),
  ({8},{9}),({10},{11}),({12},{13}),({14},{15}),({16},{17}),({18},{19}),({20},{21}),
  ({22},{23}),({24},{25}),({26},{27}),({28},{29}),({30},{31}),({32},{33}),({34},{35}),
  ({36},{37}),({38},{39})"
  </code></pre>
  
  <p>and the command parameters are like this (from VS debug):</p>
  
  <pre><code>[0] - ParameterName = "0", SqlDbType = BigInt, Value = 21400
  [1] - ParameterName = "1", SqlDbType = NVarChar, Value = "Dan Smith"
  [2] - ParameterName = "2", SqlDbType = BigInt, Value = 21401
  [3] - ParameterName = "3", SqlDbType = NVarChar, Value = "Doug Smith"
  [4] - ParameterName = "4", SqlDbType = BigInt, Value = 21402
  [5] - ParameterName = "5", SqlDbType = NVarChar, Value = "Danielle Smith"
  </code></pre>
  
  <p>The error I am getting is "Incorrect syntax near '0'."  Can someone tell me what is causing this?</p>
  
  <p>In case it matters here is where I am creating the parameter array (separate function that iterates over JSON returned from API):</p>
  
  <pre><code>    foreach (KeyValuePair&lt;string, object&gt; _attribute in _field)
      {
          // '_score' is an attribute included with each entity when doing a search
          // indicating the matching score of the query, we don't want this in the database
          if (_attribute.Key.ToString() != "_score")
          {
              _insertQuery.AppendFormat("{{{0}}},", _paramNumber);
              _paramValues.Add(new SqlParameter(_paramNumber.ToString(), _attribute.Value));
              _paramNumber++;
          }
      }
      return new object[] {_insertQuery.ToString(), _paramValues };
  </code></pre>
  
  <p>I am doing this as I am retrieving various objects from an API and then inserting into a local database.  I cannot create a class for each of these objects (requirements are to make this generic).</p>
  
  <p><strong>UPDATE</strong>: </p>
  
  <p>I updated the code to prepend the _paramNumber with "@" so each parameter is now @0, @1, etc. and I am now getting this error:</p>
  
  <pre><code>"Incorrect syntax near '@0'."
  </code></pre>
  
  <p>The insert statement is as follows:</p>
  
  <pre><code>"INSERT INTO Candidate (id, name) VALUES ({@0},{@1}),({@2},{@3}),({@4},{@5}),({@6},{@7}),
  ({@8},{@9}),({@10},{@11}),({@12},{@13}),({@14},{@15}),({@16},{@17}),({@18},{@19}),
  ({@20},{@21}),({@22},{@23}),({@24},{@25}),({@26},{@27}),({@28},{@29}),({@30},{@31}),
  ({@32},{@33}),({@34},{@35}),({@36},{@37}),({@38},{@39})"
  </code></pre>
  
  <p>and the parameters are like this:</p>
  
  <pre><code>[0] - ParameterName = "@0", SqlDbType = BigInt, Value = 21400
  [1] - ParameterName = "@1", SqlDbType = NVarChar, Value = "Dan Smith"
  [2] - ParameterName = "@2", SqlDbType = BigInt, Value = 21401
  [3] - ParameterName = "@3", SqlDbType = NVarChar, Value = "Doug Smith"
  [4] - ParameterName = "@4", SqlDbType = BigInt, Value = 21402
  [5] - ParameterName = "@5", SqlDbType = NVarChar, Value = "Danielle Smith"
  </code></pre>