Sql Type To Csharp Type - CSharp System.Reflection

CSharp examples for System.Reflection:Type

Description

Sql Type To Csharp Type

Demo Code


using System.Text;
using System.Linq;
using System.Data;
using System.Collections.Generic;
using System;// w w w .j  a va  2 s  .co m

public class Main{

        public static Type SqlTypeToCsharpType(string sqlType)
        {
            switch (sqlType.ToLower())
            {
                case "bit":
                    return typeof(Boolean);
                case "nchar":
                case "ntext":
                case "nvarchar":
                case "nvarchar2":
                case "char":
                case "text":
                case "varchar":
                case "varchar2":
                case "nclob":
                case "clob":
                case "long":
                case "rowid":
                    return typeof(String);
                case "datetime":
                case "datetime2":
                case "date":
                case "datetimeoffset":
                case "smalldatetime":
                case "time":
                case "timestamp":
                    return typeof(DateTime);
                case "interval day to second":
                    return typeof(TimeSpan);
                case "money":
                case "decimal":
                case "smallmoney":
                case "number":
                case "integer":
                    return typeof(Decimal);
                case "float":
                    return typeof(Double);
                case "smallint":
                    return typeof(Int16);
                case "int":
                case "interval year to month":
                    return typeof(int);
                case "bigint":
                    return typeof(Int64);
                case "real":
                case "binary_float":
                    return typeof(Single);
                case "tinyint":
                    return typeof(Byte);
                case "bfile":
                case "blob":
                case "long raw":
                case "raw":
                    return typeof(Byte[]);
                case "uniqueidentifier":
                    return typeof(Guid);
                case "binary":
                case "image": 
                case "udt":
                case "varbinary":
                case "variant":
                case "xml":
                default:
                    return typeof(Object);
            }
        }
}

Related Tutorials