仅此而已。我有一个现有的 DataTable,我想让它成为现有 DataSet 的一部分。关于如何去做的任何想法?我尝试了几件事,但都没有奏效......
数据集包含一组表,并且与每个集合一样,您可以使用 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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36645 次 |
| 最近记录: |