Search code examples
c#sql-serversqldbtypedbtype

What is the difference between SqlDataReader SqlTypes and DbType typed accessors?


What is the difference between SqlDataReader SqlTypes and DbType typed accessors?

When is it more appropriate to use either?


Solution

  • If your code needs to be provider agnostic and work against multiple database systems, you should avoid using SQL Server specific functionality, your code should not reference SqlDataReader at all. It should use the neutral types such as DbDataReader and then only the GetDecimal method are available.

    On the other hand, if you're happy to tie your implementation to SQL Server specifically, or you're already having to be implementation specific, then I'd suggest using the SQL Server specific accessors (e.g. GetSqlDecimal) and types, since they are more specifically aligned with the SQL Server data types.