如何通过填写数据在C#中设置ado.net
答
你可以尝试下面的下面。我建议你在网上做更多的阅读以获得更好的理解,也许会举几个例子。
// 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"]);
}
从MSDN
答
Populating a DataSet from a DataAdapter (ADO.NET)
// 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");
+0
感谢它的工作 – SUJEET
采取请通过此链接http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter_members% 28v = VS.85%29.aspx和后,如果您有任何具体问题 – V4Vendetta
可能重复[如何获取数据集值](http://stackoverflow.com/questions/2272915/how-to-get-a- dataset-value) –