本文整理汇总了C#中IDataReader.GetFieldType方法的典型用法代码示例。如果您正苦于以下问题:C# IDataReader.GetFieldType方法的具体用法?C# IDataReader.GetFieldType怎么用?C# IDataReader.GetFieldType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataReader
的用法示例。
在下文中一共展示了IDataReader.GetFieldType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
/// <summary>
/// Processes the specified <see cref="IDataReader"/>
/// when no resultClass or resultMap attribute are specified.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="reader">The reader.</param>
/// <param name="resultObject">The result object.</param>
public object Process(RequestScope request, ref IDataReader reader, object resultObject)
{
object outObject = resultObject;
if (reader.FieldCount == 1)
{
ResultProperty property = new ResultProperty();
property.PropertyName = "value";
property.ColumnIndex = 0;
property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(0));
outObject = property.GetDataBaseValue(reader);
}
else if (reader.FieldCount > 1)
{
object[] newOutObject = new object[reader.FieldCount];
int count = reader.FieldCount;
for (int i = 0; i < count; i++)
{
ResultProperty property = new ResultProperty();
property.PropertyName = "value";
property.ColumnIndex = i;
property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(i));
newOutObject[i] = property.GetDataBaseValue(reader);
}
outObject = newOutObject;
}
else
{
// do nothing if 0 fields
}
return outObject;
}
示例2: DataReaderAdapter
public DataReaderAdapter(IDataReader reader, int nrows)
: base(nrows, MakeColumnNames(reader), MakeModelRow(reader), MakeTNULL(reader))
{
_haveRow = reader.Read();
_reader = reader;
_rowStuffers = new RowStuffer[reader.FieldCount];
//_rowStuffers = new RowStuffer[reader.GetSchemaTable().Columns.Count];
for(int i = 0; i < _rowStuffers.Length; ++i)
{
Type t = reader.GetFieldType(i);
//_rowStuffers[i] = RowStuffer.GetRowStuffer(reader.GetFieldType(i));
try
{
_rowStuffers[i] = RowStuffer.GetRowStuffer(t);
}
catch(Exception e)
{
throw e;
}
if(reader.GetFieldType(i) == typeof(String))
{
_rowStuffers[i] =
//new RowStuffer.StringRowStuffer(reader.GetSchemaTable().Columns[i].MaxLength);
new RowStuffer.StringRowStuffer(30);
}
}
}
示例3: GetBoolNullCheck
public static bool GetBoolNullCheck(IDataReader reader, int ordinal)
{
try {
return reader.IsDBNull(ordinal) || (reader.GetFieldType(ordinal).Name == "Int32" ?
reader.GetInt32(ordinal) > 0 : reader.GetFieldType(ordinal).Name == "Boolean" ? reader.GetBoolean(ordinal) : Convert.ToInt32(reader.GetString(ordinal)) > 0);
} catch (Exception) {
return true;
}
}
示例4: Pivot
public static DataTable Pivot(IDataReader dataValues, string keyColumn, string pivotNameColumn, string pivotValueColumn)
{
DataTable tmp = new DataTable();
DataRow r;
string LastKey = "//dummy//";
int i, pValIndex, pNameIndex;
string s;
bool FirstRow = true;
// Add non-pivot columns to the data table:
pValIndex = dataValues.GetOrdinal(pivotValueColumn);
pNameIndex = dataValues.GetOrdinal(pivotNameColumn);
for (i = 0; i <= dataValues.FieldCount - 1; i++)
if (i != pValIndex && i != pNameIndex)
tmp.Columns.Add(dataValues.GetName(i), dataValues.GetFieldType(i));
r = tmp.NewRow();
// now, fill up the table with the data:
while (dataValues.Read())
{
// see if we need to start a new row
if (dataValues[keyColumn].ToString() != LastKey)
{
// if this isn't the very first row, we need to add the last one to the table
if (!FirstRow)
tmp.Rows.Add(r);
r = tmp.NewRow();
FirstRow = false;
// Add all non-pivot column values to the new row:
for (i = 0; i <= dataValues.FieldCount - 3; i++)
r[i] = dataValues[tmp.Columns[i].ColumnName];
LastKey = dataValues[keyColumn].ToString();
}
// assign the pivot values to the proper column; add new columns if needed:
s = dataValues[pNameIndex].ToString();
if (!tmp.Columns.Contains(s))
tmp.Columns.Add(s, dataValues.GetFieldType(pValIndex));
r[s] = dataValues[pValIndex];
}
// add that final row to the datatable:
tmp.Rows.Add(r);
// Close the DataReader
dataValues.Close();
// and that's it!
return tmp;
}
示例5: Get
/// <summary>
///
/// </summary>
/// <param name="rs"></param>
/// <param name="index"></param>
/// <returns></returns>
public override object Get(IDataReader rs, int index)
{
if (rs.GetFieldType(index) == typeof (Guid))
{
return rs.GetGuid(index);
}
if (rs.GetFieldType(index) == typeof(byte[]))
{
return new Guid((byte[])(rs[index]));
}
return new Guid(Convert.ToString(rs[index]));
}
示例6: GetValue
/// <summary>
/// Gets the value of an argument constructor.
/// </summary>
/// <param name="request">The current <see cref="RequestScope"/>.</param>
/// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
/// <param name="reader">The current <see cref="IDataReader"/>.</param>
/// <param name="keys">The keys</param>
/// <returns>The paremeter value.</returns>
public object GetValue(RequestScope request, ResultProperty mapping,
ref IDataReader reader, object keys)
{
if (mapping.TypeHandler == null ||
mapping.TypeHandler is UnknownTypeHandler) // Find the TypeHandler
{
lock(mapping)
{
if (mapping.TypeHandler == null || mapping.TypeHandler is UnknownTypeHandler)
{
int columnIndex = 0;
if (mapping.ColumnIndex == ResultProperty.UNKNOWN_COLUMN_INDEX)
{
columnIndex = reader.GetOrdinal(mapping.ColumnName);
}
else
{
columnIndex = mapping.ColumnIndex;
}
Type systemType =reader.GetFieldType(columnIndex);
mapping.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(systemType);
}
}
}
object dataBaseValue = mapping.GetDataBaseValue( reader );
request.IsRowDataFound = request.IsRowDataFound || (dataBaseValue != null);
return dataBaseValue;
}
示例7: 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;
}
示例8: DataReaderToDataSet
public static DataSet DataReaderToDataSet(IDataReader reader)
{
var ds = new DataSet();
DataTable table;
do
{
int fieldCount = reader.FieldCount;
table = new DataTable();
for (int i = 0; i < fieldCount; i++)
{
table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
}
table.BeginLoadData();
var values = new Object[fieldCount];
while (reader.Read())
{
reader.GetValues(values);
table.LoadDataRow(values, true);
}
table.EndLoadData();
ds.Tables.Add(table);
} while (reader.NextResult());
reader.Close();
return ds;
}
示例9: SpatialDbFeatureDataReader
protected internal SpatialDbFeatureDataReader(IGeometryFactory geomFactory, IDataReader internalReader,
string geometryColumn, string oidColumn)
{
_geomFactory = geomFactory;
_internalReader = internalReader;
_geometryColumn = geometryColumn;
_oidColumn = oidColumn;
for (int i = 0; i < internalReader.FieldCount; i++)
// note: GetOrdinal crashes if the column does not exist so loop through fields
{
string name = internalReader.GetName(i);
if (String.Compare(name, geometryColumn, StringComparison.CurrentCultureIgnoreCase) == 0)
_geomColumnIndex = i;
if (String.Compare(name, oidColumn, StringComparison.CurrentCultureIgnoreCase) == 0)
_oidColumnIndex = i;
if (_geomColumnIndex > -1 && _oidColumnIndex > -1)
break;
}
if (_oidColumnIndex > -1)
_oidType = _internalReader.GetFieldType(_oidColumnIndex);
}
示例10: ConverDataReaderToDataTable
public static DataTable ConverDataReaderToDataTable(IDataReader reader)
{
if (reader == null)
{
return null;
}
DataTable table = new DataTable
{
Locale = CultureInfo.InvariantCulture
};
int fieldCount = reader.FieldCount;
for (int i = 0; i < fieldCount; i++)
{
table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
}
table.BeginLoadData();
object[] values = new object[fieldCount];
while (reader.Read())
{
reader.GetValues(values);
table.LoadDataRow(values, true);
}
table.EndLoadData();
return table;
}
示例11: 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;
}
示例12: Process
/// <summary>
/// Processes the specified <see cref="IDataReader"/>
/// when a 'resultClass' attribute is specified on the statement and
/// the 'resultClass' attribute is a <see cref="IDictionary"/>.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="reader">The reader.</param>
/// <param name="resultObject">The result object.</param>
public object Process(RequestScope request, ref IDataReader reader, object resultObject)
{
object outObject = resultObject;
AutoResultMap resultMap = request.CurrentResultMap as AutoResultMap;
if (outObject == null)
{
outObject = resultMap.CreateInstanceOfResultClass();
}
int count = reader.FieldCount;
IDictionary dictionary = (IDictionary) outObject;
for (int i = 0; i < count; i++)
{
ResultProperty property = new ResultProperty();
property.PropertyName = "value";
property.ColumnIndex = i;
property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(i));
dictionary.Add(
reader.GetName(i),
property.GetDataBaseValue(reader));
}
return outObject;
}
示例13: PopulateTree
/// <summary>
///
/// </summary>
/// <param name="root"></param>
/// <param name="reader"></param>
/// <param name="prefix"></param>
public void PopulateTree(CompositeNode root, IDataReader reader, String prefix)
{
string[] fields = GetFields(reader);
int[] indexesToSkip = FindDuplicateFields(fields);
IndexedNode indexNode = new IndexedNode(prefix);
int row = 0;
while(reader.Read())
{
CompositeNode node = new CompositeNode(row.ToString());
for(int i=0; i<reader.FieldCount; i++)
{
// Is in the skip list?
if (Array.IndexOf(indexesToSkip, i) >= 0) continue;
// Is null?
if (reader.IsDBNull(i)) continue;
Type fieldType = reader.GetFieldType(i);
node.AddChildNode(new LeafNode(fieldType, fields[i], reader.GetValue(i)));
}
indexNode.AddChildNode(node);
row++;
}
root.AddChildNode(indexNode);
}
示例14: 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;
}
示例15: GetDoubleNullCheck
public static double GetDoubleNullCheck(IDataReader reader, int ordinal)
{
try {
return reader.IsDBNull(ordinal) ? 0 : reader.GetFieldType(ordinal).Name == "Double" ? reader.GetDouble(ordinal) : Convert.ToDouble(reader.GetString(ordinal));
} catch (Exception) {
return 0;
}
}