title: C# sqlDataReader.Read() causing Convertion failed error
body: <p>The query for the database is working fine and returning the rows. 
  But at some point, about 2 minutes into running the program, it crashes with the error below. </p>
  
  <blockquote>
    <p>Unhandled Exception: System.Data.SqlClient.SqlException: Conversion
    failed when converting the varchar value 'NULL' to data type int.<br>
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
    Boolean breakConnection, Action<code>1 wrapCloseInAction)    at
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
    exception, Boolean breakConnection, Action</code>1 wrapCloseInAction)    at
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
    stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)    at
    System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,
    SqlCommand cmdHandler, SqlDataReader dataStream,
    BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
    stateObj, Boolean&amp; dataReady)    at
    System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean&amp; moreRows) 
    at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean
    setTimeout, Boolean&amp; more)    at
    System.Data.SqlClient.SqlDataReader.Read()    at
    TrackChanges.Program.Main(String[] args) in
    C:\Users\ari.downey\Documents\Visual Studio
    2015\Projects\TrackChanges\TrackChanges\Program.cs:line 31 Press any
    key to continue . . .</p>
  </blockquote>
  
  <pre><code>using (SqlCommand cmd = new SqlCommand(query, conn))
  {
      conn.Open();
      SqlDataReader read = cmd.ExecuteReader();
  
      while (read.Read())
      {
          if (read[4].ToString().ToUpper() != columns[4].ToUpper())
          {
              for (int i = 0; i &lt; read.FieldCount; i++)
                  Console.Write(read[i] + " || " + columns[i] + " ");
              Console.WriteLine(" ");
          }
      }                       
      conn.Close();
  }
  </code></pre>
  
  <p>I apologize that the code is plain text. I need to ask a question to get more reputation but I have no relevant questions other than this to ask.</p>