title: c# postgresql multiple add values
body: <p>I'm playing with a PostgreSQL and c#. I'm entering multiple .AddWithValues() to fill in all of the data. This might get hairy, considering a real database will have more keys. <strong>Is there a way to combine multiple AddWithValues()s into a single line or operation?</strong></p>
  
  <p>Here is my code:</p>
  
  <pre><code>//Open the connection
  
  //Made the id as a Guid. For now just using var id = new Guid()
  
  //Insert multiple rows
  using(var command = new NpgsqlCommand())
  {
       command.Connection = connection;
       command.CommandText = "INSERT INTO testschema.testtable" +
                          "(name, id, number)" +
                          "VALUES (@name, @id, @number)";
       command.Parameters.AddWithValue("name", "Greg");
       command.Parameters.AddWithValue("id", id);
       command.Parameters.AddWithValue("number", 7);
       command.ExecuteNonQuery(); //Needs to be inside the loop
  
       //TODO: have the command text and parameters constructed once(Using the Parameters.Add for the parameters
       // and change values in the loop.
  
       //Also should have one connection open. So open just before the loop and close it after
   }
  
   //Close the connection
  </code></pre>