title: Specified cast is not valid?
body: <p>I have a table created in ASP.net and I want to populate the table with information from the database once the page has been loaded. I'm getting an error that the specified cast is not valid. What am I doing wrong?  Heres my code</p>
  
  <pre><code>public string getData()
  {
          string htmlStr = "";
  
          SqlConnection conn = new SqlConnection(connString);
          SqlCommand command = conn.CreateCommand();
          command.CommandText = "SELECT * from INFO";
          conn.Open();
          SqlDataReader reader = command.ExecuteReader();
  
          while (reader.Read())
          {
              DateTime Date = reader.GetDateTime(0);
              DateTime Time = reader.GetDateTime(1);
              htmlStr += "&lt;tr&gt;&lt;td&gt;" + Date + "&lt;/td&gt;&lt;td&gt;"  + Time + "&lt;/td&gt;&lt;/tr&gt;";                  
          }
  
          conn.Close();
  
          return htmlStr;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;table style="width:100%"&gt;
                  &lt;caption&gt;INFO&lt;/caption&gt;
                  &lt;tr&gt;
                      &lt;td&gt; Date &lt;/td&gt;
                      &lt;td&gt; Time &lt;/td&gt;
                  &lt;/tr&gt;
                      &lt;%=getData()%&gt;
                  &lt;/table&gt;
  </code></pre>
  
  <p>This is my error:</p>
  
  <p><img src="https://i.stack.imgur.com/5SaWg.png" alt="This is my error"></p>
  
  <p>It is throwing the exception on this line from the above code:</p>
  
  <pre><code>DateTime Date = reader.GetDateTime(0);
  </code></pre>