WPF開発ノウハウ集

プリペアドパラメータを使ってSQLステートメントに変数を使用する

C#の型とDbTypeの紐つけ(参考)

    Dictionary<Type, DbType> map = new Dictionary<Type, DbType> 
    {
        { typeof( Byte ), DbType.Byte },
        { typeof( UInt16 ), DbType.UInt16 },
        { typeof( UInt32 ), DbType.UInt32 },
        { typeof( UInt64 ), DbType.UInt64 },
        { typeof( SByte ), DbType.SByte },
        { typeof( Int16 ), DbType.Int16 },
        { typeof( Int32 ), DbType.Int32 },
        { typeof( Int64 ), DbType.Int64 },
        { typeof( Single ), DbType.Single },
        { typeof( Double ), DbType.Double },
        { typeof( Decimal ), DbType.Decimal },
        { typeof( DateTime ), DbType.DateTime },
        { typeof( Boolean ), DbType.Boolean },
        { typeof( Char ), DbType.StringFixedLength },
        { typeof( String ), DbType.String }
    };
    return map;