Search code examples
c#sql.netsqldbtype

How can I get the max value of SqlDbTypes like max SqlDbType.Int?


I would like to assign some string typed variables to MAximum values of some types in SQL Server 2008.

For example:

string foo = MaxValueInDbFor(SqlDbType.Int);
string boo = MaxValueInDbFor(SqlDbType.SmallInt);

How can I achieve this? Thanks


Solution

  • If I understand correctly you need this.

    var maxValue =  System.Data.SqlTypes.SqlInt16.MaxValue;
    var minValue =  System.Data.SqlTypes.SqlInt16.MinValue;
    

    Same way you can get Sql***.MaxValue or Sql***.MinValue properties for any sql types .

    Check out System.Data.SqlTypes namespace for more info.