sql - System.Data.DbType to TSQL parameter datatype -


do guys know of mapping list or ideally .net standard class or function convert system.data.dbtype enum options tsql "string" corresponding specified sql server type.

// type: system.data.dbtype // assembly: system.data, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089 // mvid: cb77dbfa-81c4-4326-93f6-e2eec5d3c28a // assembly location: c:\windows\microsoft.net\framework\v4.0.30319\system.data.dll      namespace system.data     {       /// <summary>       /// specifies data type of field, property, or parameter object of .net framework data provider.       /// </summary>       /// <filterpriority>2</filterpriority>       public enum dbtype       {         ansistring = 0,         binary = 1,         byte = 2,         boolean = 3,         currency = 4,         date = 5,         datetime = 6,         decimal = 7,         double = 8,         guid = 9,         int16 = 10,         int32 = 11,         int64 = 12,         object = 13,         sbyte = 14,         single = 15,         string = 16,         time = 17,         uint16 = 18,         uint32 = 19,         uint64 = 20,         varnumeric = 21,         ansistringfixedlength = 22,         stringfixedlength = 23,         xml = 25,         datetime2 = 26,         datetimeoffset = 27,       }     } 

example:

dbtype.int32 -> int dbtype.ansistring -> varchar dbtype.string -> nvarchar dbtype.guid -> uniqueidentifier 

thank help.

here lines of code wrote before:

 public enum recurring_dayofweek   {     sunday = 2,     monday = 4,     tuesday = 8,     wednesday = 16,     thursday = 32,     friday = 64,     saturday = 128   } 

req_param description of enum if don't have description work, in enumhelper leave example....

     system.data.sqldbtype sqldatatype =     (system.data.sqldbtype)enum.parse(typeof(system.data.sqldbtype),     enumhelper.enumdescription(req_param), true);     using system.componentmodel;  public static class enumhelper {      public enum speed     {         [description("5 metters per second")]         5 = 5,         [description("10 metters per second")]         ten = 10,         [description("15 metters per second")]         fifteen = 15,         [description("20 metters per second")]         twenty = 20,         //[description("25 metters per second")]         twentyfive = 25,        [description("30 metters per second")]         thirty = 30     }      /// <summary>     /// string value of enum attribute     /// </summary>     /// <param name="enumconstant"></param>     /// <returns>     /// string enumdesctiption = enumhelper.enumdescription(enumhelper.speed.thirty);     ///  enumdesctiption = enumhelper.enumdescription(dayofweek.monday); when there no desc returns string enum property     /// </returns>     public static string enumdescription(enum enumconstant)     {         system.reflection.fieldinfo fi = enumconstant.gettype().getfield(enumconstant.tostring());         descriptionattribute[] aattr = (descriptionattribute[])fi.getcustomattributes(typeof(descriptionattribute), false);         if (aattr.length > 0)         {           return aattr[0].description;         }         else         {             return enumconstant.tostring();         }     }    } 

be careful bit , validation c#, vb.net <--> sql


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -