本文整理匯總了C#中System.Data.DataTable.Rows屬性的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.Rows屬性的具體用法?C# DataTable.Rows怎麽用?C# DataTable.Rows使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.Rows屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: PrintRows
private void PrintRows(DataSet dataSet)
{
// For each table in the DataSet, print the values of each row.
foreach(DataTable thisTable in dataSet.Tables)
{
// For each row, print the values of each column.
foreach(DataRow row in thisTable.Rows)
{
foreach(DataColumn column in thisTable.Columns)
{
Console.WriteLine(row[column]);
}
}
}
}
private void AddARow(DataSet dataSet)
{
DataTable table;
table = dataSet.Tables["Suppliers"];
// Use the NewRow method to create a DataRow with
// the table's schema.
DataRow newRow = table.NewRow();
// Set values in the columns:
newRow["CompanyID"] = "NewCompanyID";
newRow["CompanyName"] = "NewCompanyName";
// Add the row to the rows collection.
table.Rows.Add(newRow);
}
示例2: Main
//引入命名空間
using System;
using System.IO;
using System.Data;
public class MainClass {
static void Main(string[] args) {
if (args.Length != 1)
return;
FileStream fs = new FileStream(args[0], FileMode.Open);
DataSet ds = new DataSet();
ds.ReadXml(fs);
// Use a DataTable to display the members.
DataTable mt = ds.Tables["member"];
for (int row = 0; row < mt.Rows.Count; row++) {
for (int col = 0; col < mt.Columns.Count - 1; col++) {
Console.WriteLine("{0,-10}{1}",
mt.Columns[col].Caption,
mt.Rows[row][col].ToString().Trim());
}
Console.WriteLine();
}
fs.Close();
}
}