Thursday, June 23, 2011

Mapping OleDbType with .Net Type



/***********************************************************************
/* Description: When dealing with excel files and it's data through .Net application it may require to compare the OLE datatypes(excel) and .net datatypes. Following code is compiled using VS2010 and C#.
***********************************************************************/




public static bool IsOleDBEqualToSystemType(TypeCode sysType, OleDbType oleType)
{
bool bRet = false;
switch (oleType)
{
case OleDbType.BigInt:
bRet = sysType == TypeCode.Int64;
break;
case OleDbType.Binary:
bRet = sysType == TypeCode.Byte;
break;
case OleDbType.Boolean:
bRet = sysType == TypeCode.Boolean;
break;
case OleDbType.BSTR:
bRet = sysType == TypeCode.String;
break;
case OleDbType.Char:
bRet = sysType == TypeCode.String;
break;
case OleDbType.Currency:
bRet = sysType == TypeCode.Decimal;
break;
case OleDbType.Date:
bRet = sysType == TypeCode.DateTime;
break;
case OleDbType.DBDate:
bRet = sysType == TypeCode.DateTime;
break;
case OleDbType.DBTime:
bRet = sysType == TypeCode.DateTime;
break;
case OleDbType.DBTimeStamp:
bRet = sysType == TypeCode.DateTime;
break;
case OleDbType.Decimal:
bRet = sysType == TypeCode.Decimal;
break;
case OleDbType.Double:
bRet = sysType == TypeCode.Double;
break;
case OleDbType.Integer:
bRet = sysType == TypeCode.Int32;
break;
case OleDbType.LongVarChar:
bRet = sysType == TypeCode.String;
break;
case OleDbType.LongVarWChar:
bRet = sysType == TypeCode.String;
break;
case OleDbType.Numeric:
bRet = sysType == TypeCode.Decimal;
break;
case OleDbType.Single:
bRet = sysType == TypeCode.Single;
break;
case OleDbType.SmallInt:
bRet = sysType == TypeCode.UInt16;
break;
case OleDbType.TinyInt:
bRet = sysType == TypeCode.SByte;
break;
case OleDbType.UnsignedBigInt:
bRet = sysType == TypeCode.UInt64;
break;
case OleDbType.UnsignedInt:
bRet = sysType == TypeCode.UInt32;
break;
case OleDbType.UnsignedSmallInt:
bRet = sysType == TypeCode.UInt16;
break;
case OleDbType.UnsignedTinyInt:
bRet = sysType == TypeCode.Byte;
break;
case OleDbType.VarChar:
bRet = sysType == TypeCode.String;
break;
case OleDbType.VarNumeric:
bRet = sysType == TypeCode.Decimal;
break;
case OleDbType.VarWChar:
bRet = sysType == TypeCode.String;
break;
case OleDbType.WChar:
bRet = sysType == TypeCode.String;
break;
}
return bRet;
}

Follow the link "http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbtype(v=vs.71).aspx" for more details





No comments:

Post a Comment