martedì 6 luglio 2010

ToOdbcDataType

Bene .. bene bene... dato che non credo di essere l'unico a litigare con Odbc nel realizzare un breve data provider mi sono visto costretto a realizzare anche questo simpatico oggettino....

Diciamo che è la base o il punto di partenza per la conversione fra un generico DBType e un OdbcDataType...

partendo da questo link "http://msdn.microsoft.com/en-us/library/bbw6zyha%28VS.71%29.aspx" che mamma microsoft ha ben pensato di pubblicare...
ho realizzato questo "mini" data converter..

private OdbcType ToOdbcDataType(DbType Type)
{
switch (Type.ToString())
{
case "AnsiString": return OdbcType.VarChar;
case "Boolean": return OdbcType.Bit;
case "Byte": return OdbcType.TinyInt;
case "Binary": return OdbcType.VarBinary;
case "Date": return OdbcType.Date;
case "DateTime": return OdbcType.DateTime;
case "Decimal": return OdbcType.Numeric;
case "Double": return OdbcType.Double;
case "Single": return OdbcType.Real;
case "Guid": return OdbcType.UniqueIdentifier;
case "Int16": return OdbcType.SmallInt;
case "Int32": return OdbcType.Int;
case "Int64": return OdbcType.BigInt;
case "String": return OdbcType.VarChar;
case "Time": return OdbcType.Time;

}
return OdbcType.VarChar;
}

Ipoteticamente il Valore di ritorno di default andrebbe gestito meglio .. ma l'occasione fa l'uomo "furbo"...

Nessun commento: