AnsweredAssumed Answered

How to query data with .NET and ODBC drivers?

Question asked by SuperJMN on Apr 11, 2016
Latest reply on Apr 18, 2016 by disabled_morkus

I have this question that nobody anwered:

 

http://stackoverflow.com/questions/36497236/how-to-extract-data-from-columns-using-odbc-and-filemaker

 

This is the original message.

 

I'm using FileMaker ODBC in a .NET application.

I have an IDbReader (System.Data.Odbc.OdbcDataReader) with some results. FieldCount is 8 but when I invoke this

var isNull = reader.IsDBNull(0);

It throws an exception.

However, if I invoke this code:

var str = reader.GetString(0); var isNull = reader.IsDBNull(0);

It works! So it seems that I cannot check if a value is null before retrieving the actual value. That doesn't make sense.

How is it supposed to work? I'm really out of ideas.

It seems that I have to extract fields blindly before checking for null! After I have called reader.GetString() on every field (every field is string), reader.IsDBNull() works perfecly.

The exception that is thrown is this:

'((System.Data.Odbc.OdbcDataReader)reader).IsDBNull(0)' threw an exception of type 'System.Data.Odbc.OdbcException' Data: {System.Collections.ListDictionaryInternal} ErrorCode: -2146232009 Errors: {System.Data.Odbc.OdbcErrorCollection} HResult: -2146232009 HelpLink: null InnerException: null Message: "" Source: "" StackTrace: " en System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)\r\n en System.Data.Odbc.OdbcDataReader.GetColAttribute(Int32 iColumn, SQL_DESC v3FieldId, SQL_COLUMN v2FieldId, HANDLER handler)\r\n en System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i)\r\n en System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)\r\n en System.Data.Odbc.OdbcDataReader.IsDBNull(Int32 i)" TargetSite: {Void HandleError(System.Data.Odbc.OdbcHandle, RetCode)}

This question is also related with this issue: IDbReader throwing exceptions for existing columns

Outcomes