title: DateTime2 to C# DateTime with SqlDataReader
body: <p>I realize this might be a dupe, but I've spent hours searching for the answer and can't seem to find it.</p>
  
  <p>I'm currently creating a web API that retrieves concert data.</p>
  
  <p>I have a SQL Server table that holds a start and end date, both as a <code>datetime2</code> type. I've inserted the dates in this format and they don't cause any problems when viewing the database:</p>
  
  <pre><code>2015-10-08T20:00:00.0000000+01:00
  </code></pre>
  
  <p>My model:</p>
  
  <pre><code>public class Concert
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public int LocationId { get; set; }
  
      [Column(TypeName = "DateTime2")]
      public DateTime Start { get; set; }
  
      [Column(TypeName = "DateTime2")]
      public DateTime End { get; set; }
  
      public string Description { get; set; }
      public string Url { get; set; }
  }
  </code></pre>
  
  <p>And my method in the class that brings up my database data:</p>
  
  <pre><code>    public List&lt;Concert&gt; getAll() 
      {
          List&lt;Concert&gt; concerts = new List&lt;Concert&gt;();
  
          SqlConnection connection = CasWebAPIdb.getConnection();
          String selectAll = "SELECT ConcertId, ConcertName, ConcertLocationId FROM dbo.Concerts";
          SqlCommand selectCommand = new SqlCommand(selectAll, connection);
  
          try
          {
              connection.Open();
              SqlDataReader reader = selectCommand.ExecuteReader();
              var isoDateTimeFormat = CultureInfo.InvariantCulture.DateTimeFormat;
  
              while (reader.Read())
              {
                  //Debug.WriteLine("lol: " + reader["ConcertEnd"].GetType());
  
                  Concert concert = new Concert();
  
                  concert.Id = (int)reader["ConcertId"];
                  concert.Name = reader["ConcertName"].ToString();
                  concert.LocationId = (int)reader["ConcertLocationId"];
                  concert.Start = (DateTime)reader["ConcertStart"];
                  concert.End = (DateTime)reader["ConcertEnd"];
  
                  concerts.Add(concert);
              }
          }
          catch (SqlException ex)
          {
              throw ex;
          }
          finally
          {
              connection.Close();
          }
          return concerts;
      }
  }
  </code></pre>
  
  <p>I get this error when debugging:</p>
  
  <blockquote>
    <p>An exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll but was not handled in user code</p>
  </blockquote>
  
  <p>I have tried a lot of things and followed a lot of examples and codes, but I can't seem to convert this properly. Does anybody have an idea?</p>
  
  <p><strong>solution</strong></p>
  
  <p>I forgot to add the 'concertStart' and 'concertEnd' to my query. 
  Problem solved, thanks!</p>