Advantages of SQL data types like SqlString vs String
-
Hi, I would like to know what is the advantage of using Sql types in C# like SqlString, SqlInt32,etc... versus the normal type string, int etc... The scenario: Having a class representing each table of the database. Each class has Insert, Update, Select, Delete methods (plus possible others) to perform those operations on the specific table represented by the class. Will there be a significant improvement of performance if my class variables are SQL types or not really? Thanks for the insight. Talal "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook
-
Hi, I would like to know what is the advantage of using Sql types in C# like SqlString, SqlInt32,etc... versus the normal type string, int etc... The scenario: Having a class representing each table of the database. Each class has Insert, Update, Select, Delete methods (plus possible others) to perform those operations on the specific table represented by the class. Will there be a significant improvement of performance if my class variables are SQL types or not really? Thanks for the insight. Talal "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook
Depending on how you use those classes, it could even hurt performance. Type conversion is going to occur every time you need to display or update a class instance variable that is SqlString, for example. On the other hand the conversion would normally only happen once per database read or write if the variables were normal String types. Also, it's normally better to model your classes after business objects, rather than the database structures, that makes it easier to co-ordinate multi-table updates.
-
Depending on how you use those classes, it could even hurt performance. Type conversion is going to occur every time you need to display or update a class instance variable that is SqlString, for example. On the other hand the conversion would normally only happen once per database read or write if the variables were normal String types. Also, it's normally better to model your classes after business objects, rather than the database structures, that makes it easier to co-ordinate multi-table updates.
Thank you for the advice. You're right, I do perform a lot of type conversion everytime I want to display or update data from the database. I guess I will revert back to normal types :) Talal "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook
-
Hi, I would like to know what is the advantage of using Sql types in C# like SqlString, SqlInt32,etc... versus the normal type string, int etc... The scenario: Having a class representing each table of the database. Each class has Insert, Update, Select, Delete methods (plus possible others) to perform those operations on the specific table represented by the class. Will there be a significant improvement of performance if my class variables are SQL types or not really? Thanks for the insight. Talal "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook
Hi! Don't forget that there is another big difference between Sqlxxx types and the normal types: Sqlxxx types can be null (Property
Null
). If your fields support null-values you should use Sqlxxx types. Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainers -
Hi! Don't forget that there is another big difference between Sqlxxx types and the normal types: Sqlxxx types can be null (Property
Null
). If your fields support null-values you should use Sqlxxx types. Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainersHi, Yes exactly, I do have some fields that are allowed to be null, in fact I decided to use Sqlxxx types because of that null thing, but I guess I can get around this by putting empty strings for string values and some special integer value (like -1) for int values. Thanks for pointing this out. Talal "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook