Benefits of SqlTypes?
-
i have simple question what are the benefits of using SqlTypes (especially regarding performance). I know there is the IsNull property but what else?
There is no Type called
SqlTypes
in the BCL. Do you mean theSqlType
enumeration? You should use this when using parameterized queries and addingDataColumn
s to ensure that data is represented correctly, as well as for design-time purposes and using classes like theSqlCommandBuilder
. This helps determine what type of data is represented. Imagine if all properties on every class were simply defined asobject
. How do you know what type of data to assign to a property in such a case? This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog] -
There is no Type called
SqlTypes
in the BCL. Do you mean theSqlType
enumeration? You should use this when using parameterized queries and addingDataColumn
s to ensure that data is represented correctly, as well as for design-time purposes and using classes like theSqlCommandBuilder
. This helps determine what type of data is represented. Imagine if all properties on every class were simply defined asobject
. How do you know what type of data to assign to a property in such a case? This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]I think he is referring to the various
struct
s defined in theSystem.Data.SqlTypes
namespace. Charlie if(!curlies){ return; } -
I think he is referring to the various
struct
s defined in theSystem.Data.SqlTypes
namespace. Charlie if(!curlies){ return; }Perhaps, but that's why one should be a little more descriptive. To the original poster, the documentation for the
System.Data.SqlTypes
(if that is, in fact, what you meant) explains it quite clearly:The System.Data.SqlTypes namespace provides classes for native data types within SQL Server. These classes provide a safer, faster alternative to other data types. Using the classes in this namespace helps prevent type conversion errors caused in situations where loss of precision could occur. Because other data types are converted to and from SqlTypes behind the scenes, explicitly creating and using objects within this namespace results in faster code as well.
This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]