2014-03-04 101 views

回答

2

數據集包含表的集合,並且與每個集合一樣,可以使用Add方法將表添加到數據集。
但有一件事要注意。如果您的表已經是另一個數據集的一部分(可能是因爲您使用了DataAdapter.Fill(DataSet)方法),那麼您應該先從先前的數據集表集合中刪除該表,然後再將其添加到新的數據集表中。

Dim dsNew = New DataSet() ' The dataset where you want to add your table 
Dim dt As DataTable = GetTable() ' Get the table from your storage 
Dim dsOld = dt.DataSet  ' Retrieve the DataSet where the table has been originally added 
if dsOld IsNot Nothing Then 
    dsOld.Tables.Remove(dt.TableName) ' Remove the table from its dataset tables collection 
End If 
dsNew.Tables.Add(dt) ' Add to the destination dataset.