本文整理匯總了C#中System.Data.DataTableReader.Item屬性的典型用法代碼示例。如果您正苦於以下問題:C# DataTableReader.Item屬性的具體用法?C# DataTableReader.Item怎麽用?C# DataTableReader.Item使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。
在下文中一共展示了DataTableReader.Item屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DisplayItems
private static void DisplayItems(DataTableReader reader)
{
int rowNumber = 0;
while (reader.Read())
{
Console.WriteLine("Row " + rowNumber);
for (int i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine("{0}: {1}", reader.GetName(i), reader[i]);
}
rowNumber++;
}
}
示例2: GetValueByName
private static object GetValueByName(
DataTableReader reader, string columnName)
{
// Consider when to use a procedure like this one carefully:
// if you're going to retrieve information from a column
// in a loop, it would be better to retrieve the column
// ordinal once, store the value, and use the methods
// of the DataTableReader class directly.
// Use this string-based indexer sparingly.
object columnValue = null;
try
{
columnValue = reader[columnName];
}
catch (ArgumentException ex)
{
// Throw all other errors back out to the caller.
columnValue = null;
}
return columnValue;
}