title: How to insert a C# List to database using Dapper.NET
body: <p>Using <a href="/questions/tagged/dapper" class="post-tag" title="show questions tagged &#39;dapper&#39;" rel="tag">dapper</a>, how can I insert a <code>C# List</code> to database.  Previously without <strong>dapper</strong> I used the below code to <strong><em>insert the List values to database</em></strong>.</p>
  
  <pre><code>try
  {                
      connection.Open();
  
      for (int i = 0; i &lt; processList.Count; i++)
      {
          string processQuery = "INSERT INTO PROCESS_LOGS VALUES (@Id, @st_Time, @ed_Time, @td_Time)";
          command = new SqlCommand(processQuery, connection);
          command.Parameters.Add("Id", SqlDbType.Int).Value = processList[i].ID;
          command.Parameters.Add("st_Time", SqlDbType.DateTime).Value = processList[i].ST_TIME;
          command.Parameters.Add("ed_Time", SqlDbType.DateTime).Value = processList[i].ED_TIME;
          command.Parameters.Add("td_Time", SqlDbType.DateTime2).Value = processList[i].TD_TIME;
          dataReader.Close();
          dataReader = command.ExecuteReader();
      }
  
      connection.Close();
  }
  catch (SqlException ex)
  {
      //--Handle Exception
  }
  </code></pre>
  
  <p>I'm familiar with fetching the data using <strong>dapper</strong> but this is my first try using <strong>insert query</strong>.  </p>
  
  <p>I tried the below code, using <code>Exceute</code> linked to query but stuck up with looping;  I think using dapper tool, there is no need for looping statement.</p>
  
  <pre><code>connection.Execute(processQuery ... );
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>class ProcessLog
      {
          public int ID { get; set; }
          public DateTime ST_TIME { get; set; }
          public DateTime ED_TIME { get; set; }
          public DateTime TD_TIME { get; set; }
          public string frequency { get; set; }
      }
  </code></pre>
  
  <p>Please advice on this.  <strong>FYI:</strong> I'm using <code>SQL Server 2008</code>.</p>