当前位置: 首页>>代码示例>>C#>>正文


C# OdbcDataReader.GetValues方法代码示例

本文整理汇总了C#中System.Data.Odbc.OdbcDataReader.GetValues方法的典型用法代码示例。如果您正苦于以下问题:C# OdbcDataReader.GetValues方法的具体用法?C# OdbcDataReader.GetValues怎么用?C# OdbcDataReader.GetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.Odbc.OdbcDataReader的用法示例。


在下文中一共展示了OdbcDataReader.GetValues方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DataTableFromDataReaderDataTypes

        private void DataTableFromDataReaderDataTypes(DataTable dataTypesTable, OdbcDataReader dataReader, OdbcConnection connection) {

            DataTable       schemaTable = null;
            // 

            // Build a DataTable from the reader
            schemaTable = dataReader.GetSchemaTable();

            // vstfdevdiv:479715 Handle cases where reader is empty
            if (null == schemaTable) {
                throw ADP.OdbcNoTypesFromProvider();
            }
            
            object[] getTypeInfoValues = new object[schemaTable.Rows.Count];
            DataRow dataTypesRow;

            DataColumn typeNameColumn = dataTypesTable.Columns[DbMetaDataColumnNames.TypeName];
            DataColumn providerDbTypeColumn = dataTypesTable.Columns[DbMetaDataColumnNames.ProviderDbType];
            DataColumn columnSizeColumn = dataTypesTable.Columns[DbMetaDataColumnNames.ColumnSize];
            DataColumn createParametersColumn = dataTypesTable.Columns[DbMetaDataColumnNames.CreateParameters];
            DataColumn dataTypeColumn = dataTypesTable.Columns[DbMetaDataColumnNames.DataType];
            DataColumn isAutoIncermentableColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsAutoIncrementable];
            DataColumn isCaseSensitiveColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsCaseSensitive];
            DataColumn isFixedLengthColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsFixedLength];
            DataColumn isFixedPrecisionScaleColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsFixedPrecisionScale];
            DataColumn isLongColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsLong];
            DataColumn isNullableColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsNullable];
            DataColumn isSearchableColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsSearchable];
            DataColumn isSearchableWithLikeColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsSearchableWithLike];
            DataColumn isUnsignedColumn = dataTypesTable.Columns[DbMetaDataColumnNames.IsUnsigned];
            DataColumn maximumScaleColumn = dataTypesTable.Columns[DbMetaDataColumnNames.MaximumScale];
            DataColumn minimumScaleColumn = dataTypesTable.Columns[DbMetaDataColumnNames.MinimumScale];
            DataColumn literalPrefixColumn = dataTypesTable.Columns[DbMetaDataColumnNames.LiteralPrefix];
            DataColumn literalSuffixColumn = dataTypesTable.Columns[DbMetaDataColumnNames.LiteralSuffix];
            DataColumn SQLTypeNameColumn = dataTypesTable.Columns[OdbcMetaDataColumnNames.SQLType];


            const int indexTYPE_NAME = 0;
            const int indexDATA_TYPE = 1;
            const int indexCOLUMN_SIZE = 2;
            const int indexCREATE_PARAMS = 5;
            const int indexAUTO_UNIQUE_VALUE = 11;
            const int indexCASE_SENSITIVE = 7;
            const int indexFIXED_PREC_SCALE = 10;
            const int indexNULLABLE = 6;
            const int indexSEARCHABLE = 8;
            const int indexUNSIGNED_ATTRIBUTE = 9;
            const int indexMAXIMUM_SCALE = 14;
            const int indexMINIMUM_SCALE = 13;
            const int indexLITERAL_PREFIX = 3;
            const int indexLITERAL_SUFFIX = 4;

            const int SQL_DATE_V2 = 9;
            const int SQL_TIME_V2 = 10;

            TypeMap typeMap ;


            while (dataReader.Read()) {
                dataReader.GetValues(getTypeInfoValues);
                dataTypesRow = dataTypesTable.NewRow();

                ODBC32.SQL_TYPE sqlType;

                dataTypesRow[typeNameColumn] = getTypeInfoValues[indexTYPE_NAME];
                dataTypesRow[SQLTypeNameColumn] = getTypeInfoValues[indexDATA_TYPE];

                sqlType = (ODBC32.SQL_TYPE)(Int32) Convert.ChangeType(getTypeInfoValues[indexDATA_TYPE],
                                                                      typeof(Int32), 
                                                                      (System.IFormatProvider)null);
                // if the driver is pre version 3 and it returned the v2 SQL_DATE or SQL_TIME types they need
                // to be mapped to thier v3 equlivants
                if (connection.IsV3Driver == false) {
                    if ((int)sqlType == SQL_DATE_V2) {
                        sqlType = ODBC32.SQL_TYPE.TYPE_DATE;
                    }
                    else if ((int)sqlType == SQL_TIME_V2) {
                        sqlType = ODBC32.SQL_TYPE.TYPE_TIME;
                    }
                }
                try {
                   typeMap = TypeMap.FromSqlType(sqlType);
                }
                // FromSqlType will throw an argument exception if it does not recognize the SqlType.
                // This is not an error since the GetTypeInfo DATA_TYPE may be a SQL data type or a driver specific
                // type. If there is no TypeMap for the type its not an error but it will degrade our level of
                // understanding of/ support for the type.
                catch (ArgumentException) {
                    typeMap = null;
                }

                // if we have a type map we can determine the dbType and the CLR type if not leave them null
                if (typeMap != null) {
                    dataTypesRow[providerDbTypeColumn] = typeMap._odbcType;
                    dataTypesRow[dataTypeColumn] = typeMap._type.FullName;
                    // setting isLong and isFixedLength only if we have a type map because for provider
                    // specific types we have no idea what the types attributes are if GetTypeInfo did not
                    // tell us
                    switch (sqlType) {

//.........这里部分代码省略.........
开发者ID:uQr,项目名称:referencesource,代码行数:101,代码来源:odbcmetadatafactory.cs

示例2: DataTableFromDataReaderDataTypes

        private void DataTableFromDataReaderDataTypes(DataTable dataTypesTable, OdbcDataReader dataReader, OdbcConnection connection)
        {
            DataTable schemaTable = null;
            schemaTable = dataReader.GetSchemaTable();
            if (schemaTable == null)
            {
                throw ADP.OdbcNoTypesFromProvider();
            }
            object[] values = new object[schemaTable.Rows.Count];
            DataColumn column19 = dataTypesTable.Columns[DbMetaDataColumnNames.TypeName];
            DataColumn column18 = dataTypesTable.Columns[DbMetaDataColumnNames.ProviderDbType];
            DataColumn column17 = dataTypesTable.Columns[DbMetaDataColumnNames.ColumnSize];
            DataColumn column16 = dataTypesTable.Columns[DbMetaDataColumnNames.CreateParameters];
            DataColumn column15 = dataTypesTable.Columns[DbMetaDataColumnNames.DataType];
            DataColumn column6 = dataTypesTable.Columns[DbMetaDataColumnNames.IsAutoIncrementable];
            DataColumn column14 = dataTypesTable.Columns[DbMetaDataColumnNames.IsCaseSensitive];
            DataColumn column5 = dataTypesTable.Columns[DbMetaDataColumnNames.IsFixedLength];
            DataColumn column13 = dataTypesTable.Columns[DbMetaDataColumnNames.IsFixedPrecisionScale];
            DataColumn column4 = dataTypesTable.Columns[DbMetaDataColumnNames.IsLong];
            DataColumn column3 = dataTypesTable.Columns[DbMetaDataColumnNames.IsNullable];
            DataColumn column2 = dataTypesTable.Columns[DbMetaDataColumnNames.IsSearchable];
            DataColumn column = dataTypesTable.Columns[DbMetaDataColumnNames.IsSearchableWithLike];
            DataColumn column12 = dataTypesTable.Columns[DbMetaDataColumnNames.IsUnsigned];
            DataColumn column11 = dataTypesTable.Columns[DbMetaDataColumnNames.MaximumScale];
            DataColumn column10 = dataTypesTable.Columns[DbMetaDataColumnNames.MinimumScale];
            DataColumn column9 = dataTypesTable.Columns[DbMetaDataColumnNames.LiteralPrefix];
            DataColumn column8 = dataTypesTable.Columns[DbMetaDataColumnNames.LiteralSuffix];
            DataColumn column7 = dataTypesTable.Columns[OdbcMetaDataColumnNames.SQLType];
            while (dataReader.Read())
            {
                TypeMap map;
                dataReader.GetValues(values);
                DataRow row = dataTypesTable.NewRow();
                row[column19] = values[0];
                row[column7] = values[1];
                ODBC32.SQL_TYPE sqltype = (ODBC32.SQL_TYPE) ((short) ((int) Convert.ChangeType(values[1], typeof(int), null)));
                if (!connection.IsV3Driver)
                {
                    if (sqltype == ~ODBC32.SQL_TYPE.WLONGVARCHAR)
                    {
                        sqltype = ODBC32.SQL_TYPE.TYPE_DATE;
                    }
                    else if (sqltype == ~ODBC32.SQL_TYPE.GUID)
                    {
                        sqltype = ODBC32.SQL_TYPE.TYPE_TIME;
                    }
                }
                try
                {
                    map = TypeMap.FromSqlType(sqltype);
                }
                catch (ArgumentException)
                {
                    map = null;
                }
                if (map != null)
                {
                    row[column18] = map._odbcType;
                    row[column15] = map._type.FullName;
                    switch (sqltype)
                    {
                        case ODBC32.SQL_TYPE.SS_TIME_EX:
                        case ODBC32.SQL_TYPE.SS_UTCDATETIME:
                        case ODBC32.SQL_TYPE.SS_VARIANT:
                        case ODBC32.SQL_TYPE.GUID:
                        case ODBC32.SQL_TYPE.WCHAR:
                        case ODBC32.SQL_TYPE.BIT:
                        case ODBC32.SQL_TYPE.TINYINT:
                        case ODBC32.SQL_TYPE.BIGINT:
                        case ODBC32.SQL_TYPE.BINARY:
                        case ODBC32.SQL_TYPE.CHAR:
                        case ODBC32.SQL_TYPE.NUMERIC:
                        case ODBC32.SQL_TYPE.DECIMAL:
                        case ODBC32.SQL_TYPE.INTEGER:
                        case ODBC32.SQL_TYPE.SMALLINT:
                        case ODBC32.SQL_TYPE.FLOAT:
                        case ODBC32.SQL_TYPE.REAL:
                        case ODBC32.SQL_TYPE.DOUBLE:
                        case ODBC32.SQL_TYPE.TIMESTAMP:
                        case ODBC32.SQL_TYPE.TYPE_DATE:
                        case ODBC32.SQL_TYPE.TYPE_TIME:
                        case ODBC32.SQL_TYPE.TYPE_TIMESTAMP:
                            goto Label_02F8;

                        case ODBC32.SQL_TYPE.SS_XML:
                        case ODBC32.SQL_TYPE.WLONGVARCHAR:
                        case ODBC32.SQL_TYPE.LONGVARBINARY:
                        case ODBC32.SQL_TYPE.LONGVARCHAR:
                            goto Label_02BC;

                        case ODBC32.SQL_TYPE.WVARCHAR:
                        case ODBC32.SQL_TYPE.VARBINARY:
                        case ODBC32.SQL_TYPE.VARCHAR:
                            goto Label_02DA;
                    }
                }
                goto Label_0314;
            Label_02BC:
                row[column4] = true;
                row[column5] = false;
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:OdbcMetaDataFactory.cs


注:本文中的System.Data.Odbc.OdbcDataReader.GetValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。