Search code examples
asp.netsqldatasource

What is the difference between DbType and Type in SqlParameter?


Can you explain me the difference between Type and DbType in a parameter of a datasource? What is the best pratice of assigning these two properties?


Solution

  • Type Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.

    like Int32, String, complex types

    it is for front-end referene

    ref: http://msdn.microsoft.com/en-us/library/system.type.aspx

    While DBType Specifies SQL Server-specific data type of a field, property, for use in a SqlParameter.

    ref: http://msdn.microsoft.com/en-us/library/system.data.sqldbtype.asp

    So this means: you must use Type when referencing from DB to C#/VB

    and DBType when referencing/Passing values to DB From C#/VB

    Hope this helps...