Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi every body,

I am using DataSet to receive data from database,
the procedure which fill it, put in dataset one table or three table according to the case,

the problem is that when DataSet filled with three tables it still preserve with that number of tables in its Count like:

C#
SpecificDataSet.Tables.Count

as when the case is one table only it still has 3 in its property SpecificDataSet.Tables.Count, and that cause error in my project

I used Clear method but not help me.

C#
SpecificDataSet.Clear();

C#
SpecificDataSet.Tables.Clear();


Any body have any idea

Thanks...
Posted
Updated 4-Oct-11 17:46pm
v2

When a method does not do what you except look at the documentation, the documentation is your friend not your enemy if you want to be serious about programming.

So the documentation for DataSet.Clear[^] clearly states that all rows in all the contained tables are removed. It mentions nothing about removing the contained DataTable's so it does not do that.

You retrieve the number of tables like this SpecificDataSet.Tables.Count that immediately tells me that SpecificDataSet.Tables is some form of collection and thus it most likely have a Clear method,and what do you know it does[^]. So you should write SpecificDataSet.Tables.Clear()
 
Share this answer
 
Comments
MrLonely_2 4-Oct-11 23:45pm    
Thanks man, but i used SpecificDataSet.Tables.Clear() before and not help too.
Simon Bang Terkildsen 4-Oct-11 23:46pm    
Then you're not clear about your problem SpecificDataSet.Tables.Clear() removes all the tables from the DataSet which is what you state as your problem.
MrLonely_2 4-Oct-11 23:58pm    
No man i am clear, but the problem was that the SpecificDataSet is get data form another DataSet in another method, and that later DataSet was the cause of problem as i did not used DataSet.Tables.Clear() with it.
but now i do it and it work nicely with me.
Thank you again.
Sergey Alexandrovich Kryukov 5-Oct-11 2:50am    
Good points, a 5. Generally, relying on this count is some indication of bad design of the code.
--SA
Simon Bang Terkildsen 5-Oct-11 9:38am    
Thanks for the vote
Use
C#
DataSet ds = new DataSet();
 
Share this answer
 

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