本文整理汇总了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
{
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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);
}
示例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);
}
}
}
}
示例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;
}
}
示例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();
}
}
示例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));
}
示例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());
}
}
示例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;
}
示例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;
}
示例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();
}