如何使用ado.net在C#中填充数据集

如何使用ado.net在C#中填充数据集,c#,sql-server-2005,ado.net,c#-3.0,C#,Sql Server 2005,Ado.net,C# 3.0,朋友们好 任何人都能说出如何在C#或数据表中填充数据集以及什么是dataadapter吗?您可以尝试以下方法。我建议你在网上多读些书,以便更好地理解,也许还可以举几个例子 // Assumes that customerConnection is a valid SqlConnection object. // Assumes that orderConnection is a valid OleDbConnection object. SqlDataAdapter custAdapter =

朋友们好
任何人都能说出如何在C#或数据表中填充数据集以及什么是dataadapter吗?您可以尝试以下方法。我建议你在网上多读些书,以便更好地理解,也许还可以举几个例子

// Assumes that customerConnection is a valid SqlConnection object.
// Assumes that orderConnection is a valid OleDbConnection object.
SqlDataAdapter custAdapter = new SqlDataAdapter(
  "SELECT * FROM dbo.Customers", customerConnection);
OleDbDataAdapter ordAdapter = new OleDbDataAdapter(
  "SELECT * FROM Orders", orderConnection);

DataSet customerOrders = new DataSet();

custAdapter.Fill(customerOrders, "Customers");
ordAdapter.Fill(customerOrders, "Orders");

DataRelation relation = customerOrders.Relations.Add("CustOrders",
customerOrders.Tables["Customers"].Columns["CustomerID"],
customerOrders.Tables["Orders"].Columns["CustomerID"]);

foreach (DataRow pRow in customerOrders.Tables["Customers"].Rows)
{
   Console.WriteLine(pRow["CustomerID"]);
   foreach (DataRow cRow in pRow.GetChildRows(relation))
   Console.WriteLine("\t" + cRow["OrderID"]);
}
摘自


如果你有任何特别的问题,请浏览这个链接并发帖,可能重复@SUJEET,这是我听到的讽刺吗?
// Assumes that connection is a valid SqlConnection object.
string queryString = 
  "SELECT CustomerID, CompanyName FROM dbo.Customers";
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);

DataSet customers = new DataSet();
adapter.Fill(customers, "Customers");