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


C# IDataReader.GetValue方法代码示例

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


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

示例1: BindIDataReaderToObject

 /// <summary>
 /// 绑定数据到实体
 /// </summary>
 /// <param name="reader">数据源</param>
 /// <param name="obj">实体</param>
 public static void BindIDataReaderToObject(IDataReader r, object o)
 {
     for (int i = 0; i < r.FieldCount; i++)
     {
         try
         {
             PropertyInfo propertyInfo = o.GetType().GetProperty(r.GetName(i));
             if (propertyInfo != null)
             {
                 if (r.GetValue(i) != DBNull.Value)
                 {
                     if (propertyInfo.PropertyType.IsEnum)
                     {
                         propertyInfo.SetValue(o, Enum.ToObject(propertyInfo.PropertyType, r.GetValue(i)), null);
                     }
                     else
                     {
                         propertyInfo.SetValue(o, r.GetValue(i), null);
                     }
                 }
             }
         }
         catch
         {
         }
     }
 }
开发者ID:BGCX261,项目名称:zhuji-cms-svn-to-git,代码行数:32,代码来源:DbManager.cs

示例2: CreateRowFromReader

        public override Row CreateRowFromReader(IDataReader reader)
        {
            GetSchemaTable(reader);
            Row r = new Row();
            for (int i = 0; i < reader.FieldCount; i++)
            {
                Type fType = reader.GetFieldType(i);
                if (fType == typeof(System.Decimal))
                {
                    GetDecimal(reader, r, i);
                }
                else if (fType == typeof(System.DateTime))
                {
                    object o = reader.GetValue(i);
                    if (o != DBNull.Value)
                    {
                        DateTime dtime = reader.GetDateTime(i);
                        if (dtime < MinDateTime)
                        {
                            o = NullDateTime.Add(new TimeSpan(dtime.Hour, dtime.Minute, dtime.Second));
                        }
                        r[reader.GetName(i)] = o;
                    }
                }
                else
                {
                    r[reader.GetName(i)] = reader.GetValue(i);
                }
            }

            return r;
        }
开发者ID:Zawulon,项目名称:ETL,代码行数:32,代码来源:OdbcCommandActivator.cs

示例3: CreateRowFromReader

        protected override Row CreateRowFromReader(IDataReader reader)
        {
            GetSchemaTable(reader);
            Row r = new Row();
            for (int i = 0; i < reader.FieldCount; i++)
            {
                Type fType = reader.GetFieldType(i);
                if (fType == typeof(System.Decimal))
                {
                    object o = reader.GetValue(i);
                    if (o != DBNull.Value)
                    {
                        string d = reader.GetValue(i).ToString();
                        //short scale = (short)SchemaTable.Rows[i].[4];
                        short scale = (short)SchemaTable.Rows[i].Field<short>("NumericPrecision");
                        decimal res = reader.GetDecimal(i);
                        if (scale > 0)
                            res = res / (int)(Math.Pow(10.0, scale));
                        r[reader.GetName(i)] = res;
                    }
                    else
                        r[reader.GetName(i)] = DBNull.Value;
                }
                else
                {
                    r[reader.GetName(i)] = reader.GetValue(i);
                }
            }

            return r;
        }
开发者ID:Zawulon,项目名称:ETL,代码行数:31,代码来源:DecimalPrecisionOdbc.cs

示例4: GetTotais

        /**
         * Assume que o result set em IDataReader reader contem na coluna 0 um ID (long), na coluna 1 a designacao (string),
         * na coluna 2 um valor (long) e, opcionalmente, na coluna 3 um outro valor (long).
         * 
         * Se existirem mais colunas, estas sao ignoradas.
         */
        protected List<TotalTipo> GetTotais(IDataReader reader) {
            List<TotalTipo> results = new List<TotalTipo>();
            TotalTipo tt;
            long total = 0;
            long total_editadas = 0;
            long total_eliminadas = 0;
            do {
                while (reader.Read()) {
                    tt = new TotalTipo();
                    tt.ID = System.Convert.ToInt64(reader.GetValue(0));
                    tt.Designacao = reader.GetValue(1).ToString();
                    tt.Contador = System.Convert.ToInt64(reader.GetValue(2));

                    // Quarta coluna (se existir) contem o valor de 'Editadas':
                    if (reader.FieldCount > 3) {
                        tt.Contador_Editadas = System.Convert.ToInt64(reader.GetValue(3));
                        total_editadas += tt.Contador_Editadas;
                        tt.Contador_Eliminadas = System.Convert.ToInt64(reader.GetValue(4));
                        total_eliminadas += tt.Contador_Eliminadas;
                    }
                    results.Add(tt);
                    total += tt.Contador;
                }
            } while (reader.NextResult());

            tt = new TotalTipo();
            tt.ID = -1;
            tt.Designacao = "Total";
            tt.Contador = total;
            tt.Contador_Editadas = total_editadas;
            tt.Contador_Eliminadas = total_eliminadas;
            results.Add(tt);
            return results;
        }
开发者ID:aureliopires,项目名称:gisa,代码行数:40,代码来源:EstatisticasRule.cs

示例5: CreateRowFromReader

 protected override Row CreateRowFromReader(IDataReader reader) {
     var row = new Row();
     var index = 1;
     row["TflKey"] = reader.GetValue(0);
     foreach (var k in _keys) {
         row[k] = reader.GetValue(index);
         index++;
     }
     return row;
 }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:10,代码来源:ParametersExtract.cs

示例6: Load

 /// <summary>
 /// Loads values from a data reader.
 /// </summary>
 /// <param name="reader">The data reader.</param>
 /// <param name="xIndex">The column number of the x-variable.</param>
 /// <param name="yIndex">The column number of the y-variable.</param>
 public void Load(IDataReader reader, int xIndex, int yIndex)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     if (isReadOnly) throw new InvalidOperationException();
     while (reader.Read())
     {
         if (reader.IsDBNull(xIndex) || reader.IsDBNull(yIndex)) continue;
         object xValue = reader.GetValue(xIndex);
         object yValue = reader.GetValue(yIndex);
         Add(Convert.ToDouble(xValue, CultureInfo.InvariantCulture), Convert.ToDouble(yValue, CultureInfo.InvariantCulture));
     }
 }
开发者ID:JackDetrick,项目名称:metanumerics,代码行数:18,代码来源:BivariateSample.NonPcl.cs

示例7: NullSafeGet

    public object NullSafeGet(IDataReader rs, string[] names, object owner)
    {
      int typeIndex = rs.GetOrdinal(names[0]);
      int dataIndex = rs.GetOrdinal(names[1]);
      if (rs.IsDBNull(typeIndex) || rs.IsDBNull(dataIndex))
      {
        return null;
      }

      var type = (string) rs.GetValue(typeIndex);
      var data = (string) rs.GetValue(dataIndex);
      return Deserialize(data, type);
    }
开发者ID:Gedzio,项目名称:jasondentler,代码行数:13,代码来源:JsonType.cs

示例8: Write

        public void Write(IDataReader reader)
        {
        	var columnsCount = _columnMappings.Count;
            const int rowIdIndex = 0;
            const int offsetCausedByRowId = rowIdIndex + 1;

			using(var cmd = _connection.CreateCommand())
			{
                if(_transaction != null)
			        cmd.Transaction = _transaction;
				
                cmd.CommandText = DestinationTableName;
				cmd.CommandType = CommandType.TableDirect;
				using (var rsIn = cmd.ExecuteResultSet(ResultSetOptions.Updatable))
				{
					var newRecord = rsIn.CreateRecord();
					while(reader.Read())
					{
                        for (var i = offsetCausedByRowId; i <= columnsCount; i++)
						{
							newRecord.SetValue(i, reader.GetValue(i));
						}
						rsIn.Insert(newRecord);
					}
				}
			}
        }
开发者ID:MikaelEliasson,项目名称:SisoDb-Provider,代码行数:27,代码来源:SqlCe4DbBulkCopy.cs

示例9: ReadImage

        /// <summary>
        /// Reads the image.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="ordinalPosition">The ordinal position.</param>
        /// <param name="generateThumbnail">if set to <c>true</c> [generate thumbnail].</param>
        /// <returns>System.Byte[][].</returns>
        public static byte[] ReadImage(IDataReader reader, int ordinalPosition, bool generateThumbnail = false)
        {
            if (reader == null)
                return null;

            if (string.IsNullOrEmpty(reader.GetValue(ordinalPosition).ToString()))
                return new byte[] { };

            var blob = ((OracleDataReader)reader).GetOracleBlob(ordinalPosition);

            var byteArr = new byte[blob.Length];

            blob.Read(byteArr, 0, Convert.ToInt32(blob.Length));

            using (var stream = new MemoryStream(byteArr))
            {
                var retVal = stream.ToArray();

                if (generateThumbnail && stream.Length > 0)
                {
                    var bitmap = new Bitmap(stream);
                    var image = bitmap.GetThumbnailImage(50, 50, AdoHelper.ThumbnailCallback, IntPtr.Zero);

                    using (var ms = new MemoryStream())
                    {
                        image.Save(ms, ImageFormat.Png);
                        return ms.ToArray();
                    }
                }

                return retVal;
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:40,代码来源:OracleImageReader.cs

示例10: FillRecordToReport

        /// <summary>
        /// 将 DataReader 的数据转储到 Grid++Report 的数据集中
        /// </summary>
        /// <param name="Report"></param>
        /// <param name="dr"></param>
        public static void FillRecordToReport(IGridppReport Report, IDataReader dr)
        {
            MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, dr.FieldCount)];

            //根据字段名称与列名称进行匹配,建立DataReader字段与Grid++Report记录集的字段之间的对应关系
            int MatchFieldCount = 0;
            for (int i = 0; i < dr.FieldCount; ++i)
            {
                foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
                {
                    if (String.Compare(fld.RunningDBField, dr.GetName(i), true) == 0)
                    {
                        MatchFieldPairs[MatchFieldCount].grField = fld;
                        MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
                        ++MatchFieldCount;
                        break;
                    }
                }
            }

            // Loop through the contents of the OleDbDataReader object.
            // 将 DataReader 中的每一条记录转储到Grid++Report 的数据集中去
            while (dr.Read())
            {
                Report.DetailGrid.Recordset.Append();

                for (int i = 0; i < MatchFieldCount; ++i)
                {
                    if (!dr.IsDBNull(MatchFieldPairs[i].MatchColumnIndex))
                        MatchFieldPairs[i].grField.Value = dr.GetValue(MatchFieldPairs[i].MatchColumnIndex);
                }

                Report.DetailGrid.Recordset.Post();
            }
        }
开发者ID:TGHGH,项目名称:Warehouse-2,代码行数:40,代码来源:GridReportUtility.cs

示例11: getColumnNames

 private string[] getColumnNames(IDataReader dataReader)
 {
     List<string> columnNames = new List<string> ();
     int count = dataReader.FieldCount;
     for (int index = 0; index < count; index++)
         columnNames.Add (dataReader.GetValue(index));
 }
开发者ID:macortes,项目名称:ad,代码行数:7,代码来源:PersisterHelper.cs

示例12: showValues

 /*** ****** MÉTODOS ***** ***/
 private static void showValues(IDataReader dataReader)
 {
     for ( int i =0; i < dataReader.FieldCount; i ++){
         object value = dataReader.GetValue(i);
         Console.WriteLine("Index={0} value={1} type={2}", i, value, value.GetType());
     }
 }
开发者ID:KevinSotomayor,项目名称:AD,代码行数:8,代码来源:Main.cs

示例13: CreateRowFromReader

 protected override Row CreateRowFromReader(IDataReader reader) {
     var row = new Row();
     for (var i = 0; i < _length; i++) {
         row[_fields[i]] = reader.GetValue(i);
     }
     return row;
 }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:7,代码来源:SqlEntityKeysExtractAllFromInput.cs

示例14: CreateInstance

        public object CreateInstance(IDataReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (log.IsDebug)
            {
                log.Debug(LogMessages.ObjectInfo_CreatingInstance, forType.Name);
            }

            var fieldTypes = new Type[reader.FieldCount];
            var values = new object[reader.FieldCount];

            for (int i = 0; i < reader.FieldCount; i++)
            {
                fieldTypes[i] = reader.GetFieldType(i);
                values[i] = reader.IsDBNull(i) ? null : reader.GetValue(i);
            }

            var tupleType = GetTupleType(fieldTypes);

            var tuple = Activator.CreateInstance(tupleType, values);

            return tuple;
        }
开发者ID:TrevorPilley,项目名称:MicroLite,代码行数:27,代码来源:TupleObjectInfo.cs

示例15: OfflineDataReader

        public OfflineDataReader(IDataReader reader)
        {
            schemaTable = reader.GetSchemaTable();

            //build column index lookup
            int j = 0;
            foreach (DataRow dr in schemaTable.Rows)
            {
                columnLookup[dr["ColumnName"].ToString().ToLower(CultureInfo.InvariantCulture)] = j;
                j++;
            }


            //copy data
            while (reader.Read())
            {
                object[] fields = new object[schemaTable.Rows.Count];
                for (int i = 0; i < fields.Length; i++)
                {
                    fields[i] = reader.GetValue(i);
                }
                records.Add(fields);
            }
            reader.Close();
            reader.Dispose();

            MoveFirst();
        }
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:28,代码来源:OfflineDataReader.cs


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