本文整理汇总了C#中IDataReader.GetValues方法的典型用法代码示例。如果您正苦于以下问题:C# IDataReader.GetValues方法的具体用法?C# IDataReader.GetValues怎么用?C# IDataReader.GetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataReader
的用法示例。
在下文中一共展示了IDataReader.GetValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: ResolveColumnDatas
private IEnumerable<object[]> ResolveColumnDatas(IDataReader dataReader)
{
while (dataReader.Read())
{
var objs = new object[dataReader.FieldCount];
dataReader.GetValues(objs);
yield return objs;
}
}
示例4: ToDictionariesImpl
private static IEnumerable<IDictionary<string,object>> ToDictionariesImpl(IDataReader reader)
{
var index = HomogenizedDictionaryIndex.CreateIndex(reader.GetFieldNames());
var values = new object[reader.FieldCount];
while (reader.Read())
{
reader.GetValues(values);
yield return OptimizedDictionary.Create(index, values);
}
}
示例5: ToDictionariesImpl
private static IEnumerable<IDictionary<string,object>> ToDictionariesImpl(IDataReader reader)
{
var index = reader.CreateDictionaryIndex();
var values = new object[reader.FieldCount];
while (reader.Read())
{
reader.GetValues(values);
ReplaceDbNullsWithClrNulls(values);
yield return OptimizedDictionary.Create(index, values);
}
}
示例6: ConvertDataReaderToDataSet
/// <summary>
/// Converts the data reader to data set.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>DataSet.</returns>
public static DataSet ConvertDataReaderToDataSet(IDataReader reader)
{
DataSet ds = new DataSet();
DataTable dataTable = new DataTable();
DataTable schemaTable = reader.GetSchemaTable();
DataRow row;
string columnName;
DataColumn column;
int count = schemaTable.Rows.Count;
for (int i = 0; i < count; i++)
{
row = schemaTable.Rows[i];
columnName = (string)row["ColumnName"];
column = new DataColumn(columnName, (Type)row["DataType"]);
dataTable.Columns.Add(column);
}
ds.Tables.Add(dataTable);
object[] values = new object[count];
try
{
dataTable.BeginLoadData();
while (reader.Read())
{
reader.GetValues(values);
dataTable.LoadDataRow(values, true);
}
}
finally
{
dataTable.EndLoadData();
reader.Close();
}
return ds;
}
示例7: DisconnectedReader
/// <summary>
/// Caches a data reader to enable disconnected data access via the IDataReader interface.
/// </summary>
/// <param name="reader">The IDataReader to cache.</param>
public DisconnectedReader(IDataReader reader)
{
// Cache field information
this.fields = new FieldInfo[reader.FieldCount];
this.ordinals = new Hashtable(StringComparer.OrdinalIgnoreCase);
for (int index = 0; index < fields.Length; index++)
{
FieldInfo field = new FieldInfo();
field.Name = reader.GetName(index);
field.Type = reader.GetFieldType(index);
field.DataTypeName = reader.GetDataTypeName(index);
fields[index] = field;
if (!ordinals.Contains(field.Name))
ordinals.Add(field.Name, index);
}
// Cache schema info
schema = reader.GetSchemaTable();
// Cache row data
rows = new ArrayList();
while (reader.Read())
{
object[] values = new object[fields.Length];
reader.GetValues(values);
rows.Add(values);
}
// Cache additional results
if (reader.NextResult())
nextResult = new DisconnectedReader(reader);
// Close the reader once all data has been cached
else
reader.Dispose();
// Set the record index before the first record;
this.recordIndex = -1;
this.lastIndex = rows.Count - 1;
}
示例8: Write
public void Write(IDataReader dataReader, string[] names, int count)
{
if (dataReader == null)
{
throw new ArgumentNullException("dataReader");
}
if (count < 0)
{
throw new ArgumentException("count less than 0");
}
if (this.columnIndex > 0)
{
this.WriteNewLine();
}
for (int row = 0; row < count; row++)
{
if (!dataReader.Read())
{
break;
}
object[] values = null;
if (names != null)
{
values = new object[names.Length];
for (int nameIndex = 0; nameIndex < names.Length; nameIndex++)
{
values[nameIndex] = dataReader[names[nameIndex]];
}
}
else
{
values = new object[dataReader.FieldCount];
dataReader.GetValues(values);
}
foreach (object value in values)
{
if (value == DBNull.Value)
{
this.Write(string.Empty);
}
else if (value == null)
{
this.Write(string.Empty);
}
else
{
this.Write(value.ToString());
}
}
this.WriteNewLine();
}
}
示例9: buildShape
/// <summary>
///
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
private PrimitiveBaseShape buildShape(IDataReader row)
{
PrimitiveBaseShape s = new PrimitiveBaseShape();
float ScaleX = 0;
float ScaleY = 0;
float ScaleZ = 0;
object[] o = new object[row.FieldCount];
row.GetValues(o);
for (int i = 0; i < o.Length; i++)
{
string name = row.GetName(i);
#region Switch
switch (name)
{
case "ScaleX":
ScaleX = Convert.ToSingle(o[i]);
break;
case "ScaleY":
ScaleY = Convert.ToSingle(o[i]);
break;
case "ScaleZ":
ScaleZ = Convert.ToSingle(o[i]);
break;
case "PCode":
s.PCode = Convert.ToByte(o[i]);
break;
case "PathBegin":
s.PathBegin = Convert.ToUInt16(o[i]);
break;
case "PathEnd":
s.PathEnd = Convert.ToUInt16(o[i]);
break;
case "PathScaleX":
s.PathScaleX = Convert.ToByte(o[i]);
break;
case "PathScaleY":
s.PathScaleY = Convert.ToByte(o[i]);
break;
case "PathShearX":
s.PathShearX = Convert.ToByte(o[i]);
break;
case "PathShearY":
s.PathShearY = Convert.ToByte(o[i]);
break;
case "PathSkew":
s.PathSkew = Convert.ToSByte(o[i]);
break;
case "PathCurve":
s.PathCurve = Convert.ToByte(o[i]);
break;
case "PathRadiusOffset":
s.PathRadiusOffset = Convert.ToSByte(o[i]);
break;
case "PathRevolutions":
s.PathRevolutions = Convert.ToByte(o[i]);
break;
case "PathTaperX":
s.PathTaperX = Convert.ToSByte(o[i]);
break;
case "PathTaperY":
s.PathTaperY = Convert.ToSByte(o[i]);
break;
case "PathTwist":
s.PathTwist = Convert.ToSByte(o[i]);
break;
case "PathTwistBegin":
s.PathTwistBegin = Convert.ToSByte(o[i]);
break;
case "ProfileBegin":
s.ProfileBegin = Convert.ToUInt16(o[i]);
break;
case "ProfileEnd":
s.ProfileEnd = Convert.ToUInt16(o[i]);
break;
case "ProfileCurve":
s.ProfileCurve = Convert.ToByte(o[i]);
break;
case "ProfileHollow":
s.ProfileHollow = Convert.ToUInt16(o[i]);
break;
case "State":
s.State = Convert.ToByte(o[i]);
break;
case "Texture":
byte[] textureEntry = (byte[])o[i];
s.TextureEntry = textureEntry;
break;
case "ExtraParams":
s.ExtraParams = (byte[])o[i];
break;
case "UUID":
//.........这里部分代码省略.........
示例10: MapToDataTable
private DataTable MapToDataTable(IDataReader reader)
{
DataTable dataTable = new DataTable();
dataTable.TableName = "FlagInfo";
DataColumn dataColumn;
dataColumn = dataTable.Columns.Add("FlagId", typeof(string));
dataColumn.MaxLength = 15;
dataColumn = dataTable.Columns.Add("FlagName", typeof(string));
dataColumn.MaxLength = 50;
dataColumn.AllowDBNull = false;
dataColumn = dataTable.Columns.Add("FlagNameFr", typeof(string));
dataColumn.MaxLength = 75;
dataColumn = dataTable.Columns.Add("FlagDescription", typeof(string));
dataColumn.MaxLength = 4000;
dataColumn = dataTable.Columns.Add("FlagDescriptionFr", typeof(string));
dataColumn.MaxLength = 4000;
dataColumn = dataTable.Columns.Add("SalesOrg", typeof(string));
dataColumn.MaxLength = 4;
dataColumn.AllowDBNull = false;
dataColumn = dataTable.Columns.Add("DistributionChannel", typeof(string));
dataColumn.MaxLength = 2;
dataColumn.AllowDBNull = false;
dataColumn = dataTable.Columns.Add("CategoryId", typeof(string));
dataColumn.MaxLength = 15;
dataTable.Columns.Add("Sequence", typeof(int));
dataTable.BeginLoadData();
object[] values = new object[reader.FieldCount];
while (reader.Read())
{
reader.GetValues(values);
dataTable.LoadDataRow(values, true);
}
dataTable.EndLoadData();
return dataTable;
}
示例11: ResultMapEntity
///// <summary>
///// 给指定的参数赋值
///// </summary>
///// <param name="paramName"></param>
///// <param name="paramValue"></param>
///// <remarks></remarks>
//public void SetParameterValue(string paramName, object paramValue)
//{
// for (int I = 0; I <= _DataParameters.Length - 1; I++)
// {
// if (_DataParameters[I].ParameterName == paramName)
// {
// _DataParameters[I].Value = paramValue;
// return;
// }
// }
// throw new Exception("没有找到指定的参数名:" + paramName);
//}
///// <summary>
///// 指定参数替换类型的参数赋值方法,paramName 不带Me.ParaChar 或者 "#"限定符
///// </summary>
///// <param name="paramName">参数名</param>
///// <param name="paramValue">参数值</param>
///// <param name="paramType">参数类型</param>
///// <remarks></remarks>
//public void SetParameterValue(string paramName, string paramValue, enumParamType paramType)
//{
// if (paramType == enumParamType.DataParameter)
// {
// SetParameterValue(paramName, paramValue);
// }
// else
// {
// if (_SqlText == null | _SqlText == string.Empty)
// {
// throw new Exception("无法设置替换参数,可能命令没有初始化.");
// }
// _SqlText = _SqlText.Replace(this.ParaChar + "%" + paramName + "%", paramValue);
// }
//}
/// <summary>
/// 将DataReader中的结果数据映射到实体对象
/// </summary>
/// <param name="reader">数据阅读器</param>
/// <param name="result">实体对象实例</param>
/// <returns>填充后的实体对象</returns>
/// <remarks></remarks>
public EntityBase ResultMapEntity(IDataReader reader, EntityBase result)
{
using (reader)
{
//if (result!=null && reader.Read())
//{
// for (int i = 0; i < reader.FieldCount; i++)
// {
// if (!reader.IsDBNull(i))
// result.PropertyList [reader.GetName(i)]= reader.GetValue(i);
// }
//}
if (reader.Read())
{
int fcount = reader.FieldCount;
string[] names = new string[fcount];
for (int i = 0; i < fcount; i++)
names[i] = reader.GetName(i);
object[] values = new object[fcount];
reader.GetValues(values);
result.PropertyNames = names;
result.PropertyValues = values;
}
}
return result;
}
示例12: DataTableFromDataReaderProcedures
private DataTable DataTableFromDataReaderProcedures(IDataReader reader, string tableName,Int16 procedureType) {
// Build a DataTable from the reader
// set up the column structure of the data table from the reader
object[] values;
DataTable resultTable = NewDataTableFromReader(reader, out values, tableName);
// populate the data table from the data reader
int positionOfProcedureType = 7;
while (reader.Read()) {
reader.GetValues(values);
// the column type should always be short but need to check just in case its null
if (values[positionOfProcedureType].GetType() == typeof(short)) {
if ((short)values[positionOfProcedureType] == procedureType) {
resultTable.Rows.Add(values);
}
}
}
return resultTable;
}
示例13: GetRow
private object[] GetRow(IDataReader reader)
{
object[] row = new object[reader.FieldCount];
reader.GetValues(row);
return row;
}
示例14: DataTableFromDataReader
private DataTable DataTableFromDataReader(IDataReader reader, string tableName)
{
object[] objArray;
DataTable table = this.NewDataTableFromReader(reader, out objArray, tableName);
while (reader.Read())
{
reader.GetValues(objArray);
table.Rows.Add(objArray);
}
return table;
}
示例15: DataTableFromDataReaderProcedures
private DataTable DataTableFromDataReaderProcedures(IDataReader reader, string tableName, short procedureType)
{
object[] objArray;
DataTable table = this.NewDataTableFromReader(reader, out objArray, tableName);
int index = 7;
while (reader.Read())
{
reader.GetValues(objArray);
if ((objArray[index].GetType() == typeof(short)) && (((short) objArray[index]) == procedureType))
{
table.Rows.Add(objArray);
}
}
return table;
}