如何将DataTable启动到数据集的第一个数据表中? [英] How can I initiate a DataTable into first datatable of a dataset ?
本文介绍了如何将DataTable启动到数据集的第一个数据表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为dt的数据表。
现在我想把这个DataTable保存到数据集中。其中dt将作为第一个表放置。如果我将新数据集声明为
I have a datatable named dt.
Now I want to keep this DataTable into the dataset. Where dt will placed as first table. if I declare a new dataset as
DataSet dset=new DataSet()
然后我想把dt保持在dset.Tables [0]的位置。
有可能吗?
如果可能的话请提供代码。
Then I want to keep dt in the position dset.Tables[0].
is it possible ?
If possible then please provide the code.
推荐答案
您添加的第一个DataTable将是第一个,依此类推。很明显,在你的情况下它将是table [0]。
问候..
The first DataTable you add will be the first one, and so on. Its obvious that it will be tables[0] in your case.
Regards..
Rohan已经回答了这个问题。如果你想让它成为第一个表,那么先添加它。但是,我建议按名称引用,而不是依赖于特定顺序的索引。
你可以这样做:
Rohan already answered the question. If you want it to be the first Table then add it first. However, I would suggest referencing by name instead of relying on indexing being in a specific order.
You can do this:
myDataSet.Tables["SomeTable"]
而不是
instead of
myDataSet.Tables[0];
然后,当数据集中有多个数据集并且排序不重要时,您知道正在访问正确的数据表。
Then you know you're accessing the right datatable when there are more than one in a dataset and ordering is not important.
这篇关于如何将DataTable启动到数据集的第一个数据表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文