2011-09-02 47 views
-1

朋友你好 任何機構可以告訴如何填補在C#中的數據集或數據表,什麼是DataAdapter的如何通過填寫數據在C#中設置ado.net

+0

採取請通過此鏈接http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter_members% 28v = VS.85%29.aspx和後,如果您有任何具體問題 – V4Vendetta

+0

可能重複[如何獲取數據集值](http://stackoverflow.com/questions/2272915/how-to-get-a- dataset-value) –

回答

1

你可以嘗試下面的下面。我建議你在網上做更多的閱讀以獲得更好的理解,也許會舉幾個例子。

// 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

+0

感謝您的努力 – SUJEET

+0

@SUJE ET,是我聽到的諷刺嗎? – Jethro

3

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

相關問題