Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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()


Then I want to keep dt in the position dset.Tables[0].

is it possible ?
If possible then please provide the code.
Posted
Comments
Thanks7872 18-Jun-14 3:16am    
The first DataTable you add will be the first one, and so on. What is the issue?
sachi Dash 18-Jun-14 3:27am    
I already use this code
dset.Tables.Add(newDT)

But I want to make sure for this reason I have given this post. Anyway thanks!
Thanks7872 18-Jun-14 4:37am    
Its garunteed to be tables[0] in this case.
ZurdoDev 18-Jun-14 7:34am    
I think you answered it. Seems pretty obvious. I think you should post as solution.
Thanks7872 18-Jun-14 7:41am    
Done. Thank you.

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..
 
Share this answer
 
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:
C#
myDataSet.Tables["SomeTable"]

instead of
C#
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.
 
Share this answer
 
Comments
Thanks7872 18-Jun-14 7:42am    
Well said. +5..!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900