ODBC differs from ADO.NET when querying CHAR columns... why/how?

  • I am upgrading a legacy application to .NET and it now uses ADO.NET rather than ODBC. However, I have found that when querying CHAR columns ODBC always pads them to their column length whereas ADO.NET treats them properly by giving you their actual data i.e. if the column was created with ANSI_PADDING on then it will be padded and with ANSI_PADDED off it will be trimmed. This is actually causing problems in the new application because the legacy code expected the consistency of ODBC. Does anyone know if there is a simple way to make ADO.NET behave in the same way as ODBC?

  • If your cast your items as Chars in your T-SQL/procedures, that normally works for me. Though I frequently work the opposite problem and have to repeatedly trim spaces off.

    edit: CAST, not designing them as chars but throw in the extra CAST b/c it clues the ado.net code what to expect

  • Thanks for your reply. My first on this board :-). Because of the number of queries possibly affected I'm hoping to avoid having to change them all. Obviously this may not be possible but I'm holding out for now ;-).

    So any other suggestions still most appreciated...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply