本文整理汇总了C#中IDataReader.GetName方法的典型用法代码示例。如果您正苦于以下问题:C# IDataReader.GetName方法的具体用法?C# IDataReader.GetName怎么用?C# IDataReader.GetName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataReader
的用法示例。
在下文中一共展示了IDataReader.GetName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: GenerateInsertStatements
public static string GenerateInsertStatements(IDataReader reader, string table, ISqlDialect dialect = null)
{
StringBuilder sbAll = new StringBuilder();
while (reader.Read())
{
var sb = new StringBuilder();
sb.Append("INSERT INTO ");
sb.Append(table);
sb.Append(" (");
for (var i = 0; i < reader.FieldCount; i++)
{
if (i > 0)
sb.Append(", ");
sb.Append(reader.GetName(i));
}
sb.Append(")\r\nVALUES (");
for (var i = 0; i < reader.FieldCount; i++)
{
if (i > 0)
sb.Append(", ");
sb.Append("/*");
sb.Append(reader.GetName(i));
sb.Append(":*/ ");
var value = reader.GetValue(i);
if (value == null ||
value == DBNull.Value)
sb.Append("NULL");
else if (value is DateTime)
sb.Append(((DateTime)value).ToSql(dialect));
else if (value is Int32 || value is Int16 || value is Boolean || value is Int64)
sb.Append(Serenity.Invariants.ToInvariant(Convert.ToInt64(value)));
else if (value is Double || value is Decimal || value is float)
sb.Append(Serenity.Invariants.ToInvariant(Convert.ToDecimal(value)));
else if (value is String)
sb.Append(((string)value).ToSql(dialect));
else
sb.Append(value.ToString().ToSql(dialect));
}
sb.Append(");");
sbAll.AppendLine(sb.ToString());
sbAll.AppendLine();
}
return sbAll.ToString();
}
示例4: getColumnNames
private string[] getColumnNames(IDataReader dataReader)
{
List<string> columnNames = new List<string>();
for (int index = 0; index < dataReader.FieldCount; index++)
columnNames.Add (dataReader.GetName (index));
return columnNames.ToArray ();
}
示例5: AppendColumns
public void AppendColumns(TreeView treeView, IDataReader dataReader)
{
for (int index = 0; index < dataReader.FieldCount; index++)
{
//Console.WriteLine("el indice es: {0}", index);
treeView.AppendColumn (dataReader.GetName (index), new CellRendererText(), "text", index);
//treeView.AppendColumn ("columna1", new CellRendererText(), "text",index);
}
//Añadimos la columna de la cantidad porque en la BBDD no tenemos este campo.
TreeViewColumn cantidad = new TreeViewColumn();
cantidad.Title = "Cantidad";
CellRendererText cant = new CellRendererText();
cantidad.PackStart(cant, true);
cantidad.AddAttribute(cant,"text",4);
//para mostrar las imágenes
//CellRendererPixbuf cellRendererPixbuf = new CellRendererPixbuf();
//prueba para cambiar tamaño letra
cantidad.Sizing = TreeViewColumnSizing.Fixed;
cantidad.FixedWidth = 200;
treeView.AppendColumn(cantidad);
}
示例6: 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
{
}
}
}
示例7: createCsvFile
public static void createCsvFile(IDataReader reader, StreamWriter writer)
{
string Delimiter = "\"";
string Separator = ",";
// write header row
for (int columnCounter = 0; columnCounter < reader.FieldCount; columnCounter++)
{
if (columnCounter > 0)
{
writer.Write(Separator);
}
writer.Write(Delimiter + reader.GetName(columnCounter) + Delimiter);
}
writer.WriteLine(string.Empty);
// data loop
while (reader.Read())
{
// column loop
for (int columnCounter = 0; columnCounter < reader.FieldCount; columnCounter++)
{
if (columnCounter > 0)
{
writer.Write(Separator);
}
writer.Write(Delimiter + reader.GetValue(columnCounter).ToString().Replace('"', '\'') + Delimiter);
} // end of column loop
writer.WriteLine(string.Empty);
} // data loop
writer.Flush();
}
示例8: TableForm
public TableForm(string name, IDataReader rdr)
{
DataGridView dgv = new DataGridView();
dgv.Dock = DockStyle.Fill;
DataGridViewTextBoxCell template = new DataGridViewTextBoxCell();
template.Style.Font = new Font("DejaVu Sans",10);
for (int i = 0;i < rdr.FieldCount;i++)
{
DataGridViewColumn col = new DataGridViewColumn(template);
col.Name = rdr.GetName(i);
dgv.Columns.Add(col);
}
while (rdr.Read())
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dgv);
for (int i = 0;i < rdr.FieldCount;i++)
{
object val = rdr[i];
if (val is byte[])
{
val = Encoding.UTF8.GetString((byte[])val);
}
row.Cells[i].Value = val;
}
dgv.Rows.Add(row);
}
Controls.Add(dgv);
}
示例9: getColumnNames
private static string[] getColumnNames(IDataReader dataReader)
{
string[] names = new string[ dataReader.FieldCount ];
for(int i = 0; i < dataReader.FieldCount; i++)
names[ i ] = dataReader.GetName(i);
return names;
}
示例10: Columns
private static IEnumerable<string> Columns(IDataReader reader)
{
for(var i = 0; i < reader.FieldCount; i++)
{
yield return reader.GetName(i);
}
}
示例11: 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();
}
}
示例12: 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);
}
示例13: CGIResponseData
public CGIResponseData(IDataReader reader)
{
Captions = new string[reader.FieldCount];
DataTypes = new string[reader.FieldCount];
for (var ordinal = 0; ordinal < Captions.Length; ordinal++)
{
Captions[ordinal] = reader.GetName(ordinal);
DataTypes[ordinal] = reader.GetDataTypeName(ordinal);
}
var rows = new List<string[]>(1000);
while (reader.Read())
{
var row = new string[Captions.Length];
for (var ordinal = 0; ordinal < Captions.Length; ordinal++)
{
if (reader.IsDBNull(ordinal))
{
row[ordinal] = null;
}
else
{
var value = reader.GetValue(ordinal);
row[ordinal] = value == null ? null : value.ToString();
}
}
rows.Add(row);
}
Values = rows.ToArray();
}
示例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 instance = new ExpandoObject();
var dictionary = (IDictionary<string, object>)instance;
for (int i = 0; i < reader.FieldCount; i++)
{
var columnName = reader.GetName(i);
if (!"MicroLiteRowNumber".Equals(columnName))
{
var value = reader.IsDBNull(i) ? null : reader.GetValue(i);
dictionary[columnName] = value;
}
}
return instance;
}
示例15: 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;
}