using System;
using System.Data;
class Program
{
static void Main()
{
// 创建一个新的DataSet对象
DataSet dataSet = new DataSet("MyDataSet");
// 创建一个DataTable并添加到DataSet中
DataTable table = new DataTable("Customers");
dataSet.Tables.Add(table);
// 添加列到DataTable
table.Columns.Add("CustomerID", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("City", typeof(string));
// 添加行到DataTable
table.Rows.Add(1, "John Doe", "New York");
table.Rows.Add(2, "Jane Smith", "Los Angeles");
table.Rows.Add(3, "Sam Brown", "Chicago");
// 遍历DataTable中的数据
foreach (DataRow row in table.Rows)
{
Console.WriteLine($"CustomerID: {row["CustomerID"]}, Name: {row["Name"]}, City: {row["City"]}");
}
}
}
DataSet dataSet = new DataSet("MyDataSet"); 创建了一个名为 MyDataSet 的 DataSet 对象。DataTable table = new DataTable("Customers"); 创建了一个名为 Customers 的 DataTable,并将其添加到 DataSet 中。table.Columns.Add 方法为 DataTable 添加列,指定了列名和数据类型。table.Rows.Add 方法向 DataTable 中添加行数据。foreach 循环遍历 DataTable 中的每一行,并打印出每一行的数据。这个示例展示了如何创建、填充和遍历 DataSet 和 DataTable 中的数据。
上一篇:c#基础
下一篇:c#字符串拼接
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站