本文整理汇总了C#中System.Data.DataSet.Tables属性的典型用法代码示例。如果您正苦于以下问题:C# DataSet.Tables属性的具体用法?C# DataSet.Tables怎么用?C# DataSet.Tables使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Data.DataSet
的用法示例。
在下文中一共展示了DataSet.Tables属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintRows
private void PrintRows(DataSet dataSet)
{
// For each table in the DataSet, print the row values.
foreach(DataTable table in dataSet.Tables)
{
foreach(DataRow row in table.Rows)
{
foreach (DataColumn column in table.Columns)
{
Console.WriteLine(row[column]);
}
}
}
}
示例2: Main
//引入命名空间
using System;
using System.Data;
using System.Data.SqlClient;
class MultipleDataTables
{
public static void Main()
{
SqlConnection mySqlConnection =new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText =
"SELECT TOP 2 ID, FirstName, LastName " +
"FROM Employee " +
"ORDER BY ID;" +
"SELECT ID, LastName " +
"FROM MyEmployee " +
"WHERE ID = 9;";
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = mySqlCommand;
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
int numberOfRows = mySqlDataAdapter.Fill(myDataSet);
Console.WriteLine("numberOfRows = " + numberOfRows);
mySqlConnection.Close();
myDataSet.Tables["Table"].TableName = "Employee";
myDataSet.Tables["Table1"].TableName = "MyEmployee";
foreach (DataTable myDataTable in myDataSet.Tables) {
Console.WriteLine("\nReading from the " +
myDataTable.TableName + "DataTable");
foreach (DataRow myDataRow in myDataTable.Rows)
{
foreach (DataColumn myDataColumn in myDataTable.Columns)
{
Console.WriteLine(myDataColumn + "= " +
myDataRow[myDataColumn]);
}
}
}
}
}