title: How to insert multiple rows into an database in C#/ADO.NET?
body: <p>I've got a DataTable which has a number of records.</p>
  
  <p>I've tried the following code for iterating through the DataTable and inserting into the database, but I am receiving an error message saying that the parameters have not been declared:</p>
  
  <pre><code>       using (SqlCommand command = new SqlCommand(("My insert statement"), connection))
                      {
  
                          SqlParameter param1 = new SqlParameter();
                          SqlParameter param2 = new SqlParameter();
  
                          param1.ParameterName = "@ProductID";
                          param2.ParameterName = "@ID";
  
                          foreach (DataRow row in table.Rows)
                          {
                              param1.Value = row[0].ToString();
                              param2.Value = row[1].ToString();
  
                              command.ExecuteNonQuery();
                          }
  
                      }
  </code></pre>
  
  <p>Any ideas? Please do not suggest stored procedures - I'd like to do this through this method or something similar.</p>