Odbc parses String as Date using internalGetDate? <p>I am attempting to convert a bit of code I wrote for SQL Server connections to work with an Odbc data source. I've been running into a bit of an issue with OdbcDataReader.GetValue(int) attempting to call OdbcDataReader.internalGetDate for a string field.</p> <p>Here is the code I am currently using for getting the value:</p> <pre><code>private static void ReadRecord&lt;T&gt;(IDataRecord record, T myClass) { .... inside loop of datarecord fields .... var value = record.GetValue(i); pi.SetValue(myClass, value == DBNull.Value ? null : Convert.ChangeType(value, record.GetFieldType(i)), null); </code></pre> <p>When I execute this against a specific 4D data table using Odbc, I get a OdbcException with no Message attached to it. The exception stack trace shows that internalGetDate was used.</p> <pre><code>at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype, Int32 cb, Int32&amp; cbLengthOrIndicator) at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype) at System.Data.Odbc.OdbcDataReader.internalGetDate(Int32 i) at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i, TypeMap typemap) at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i) at System.Data.Odbc.DbCache.AccessIndex(Int32 i) at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i) </code></pre> <p>I reviewed the reference source <a href="http://referencesource.microsoft.com/#System.Data/System/Data/Odbc/OdbcDataReader.cs,495" rel="nofollow">here</a> which shows that GetSqlType is executed to determine the function to call in a later GetValue() call. I wrote this code to check the SqlType of the index in question</p> <pre><code>var odbcdatareader = typeof(OdbcDataReader); var method = odbcdatareader.GetMethod("GetSqlType", BindingFlags.Instance | BindingFlags.NonPublic); var type = method.Invoke(record, new object[] { i }); var typemap = odbcdatareader.Assembly.GetType("System.Data.Odbc.TypeMap"); var typemapodbctype = typemap.GetField("_odbcType", BindingFlags.Instance | BindingFlags.NonPublic); var typemapdbtype = typemap.GetField("_dbType", BindingFlags.Instance | BindingFlags.NonPublic); var typemaptype = typemap.GetField("_type", BindingFlags.Instance | BindingFlags.NonPublic); var typemapsqltype = typemap.GetField("_sql_type", BindingFlags.Instance | BindingFlags.NonPublic); Console.WriteLine("{0}, {1}, {2}, {3}", typemapodbctype.GetValue(type), typemapdbtype.GetValue(type), typemaptype.GetValue(type), typemapsqltype.GetValue(type)); </code></pre> <p>The results of this check are:</p> <pre><code>Char, AnsiStringFixedLength, System.String, CHAR </code></pre> <p>Why would Odbc's GetSqlType be reporting this as a CHAR but then using internalGetDate to try and parse the data? Am I missing something obvious?</p> <p>Even weirder is when I call GetString() on that index, I also get an error with internalGetDate().</p> <pre><code>at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype, Int32 cb, Int32&amp; cbLengthOrIndicator) at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype) at System.Data.Odbc.OdbcDataReader.internalGetDate(Int32 i) at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i, TypeMap typemap) at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i) at System.Data.Odbc.DbCache.AccessIndex(Int32 i) at System.Data.Odbc.OdbcDataReader.internalGetString(Int32 i) at System.Data.Odbc.OdbcDataReader.GetString(Int32 i) </code></pre>