<p>I currently use a DataTable to get results from a database which I can use in my code.</p>

<p>However, many example on the web show using a DataSet instead and accessing the table(s) through the collections method.</p>

<p>Is there any advantage, performance wise or otherwise, of using DataSets or DataTables as a storage method for SQL results?</p>

[{'answer_id': 2254, 'author': 'Karl Seguin', 'author_id': 34, 'author_profile': 'https://Stackoverflow.com/users/34', 'pm_score': 3, 'selected': False, 'text': "<p>in 1.x there used to be things DataTables couldn't do which DataSets could (don't remember exactly what). All that was changed in 2.x.  My guess is that's why a lot of examples still use DataSets.  DataTables should be quicker as they are more lightweight. If you're only pulling a single resultset, its your best choice between the two.</p>\n"}, {'answer_id': 2258, 'author': 'ZombieSheep', 'author_id': 377, 'author_profile': 'https://Stackoverflow.com/users/377', 'pm_score': 8, 'selected': True, 'text': '<p>It really depends on the sort of data you\'re bringing back.  Since a DataSet is (in effect) just a collection of DataTable objects, you can return multiple distinct sets of data into a single, and therefore more manageable, object.  </p>\n\n<p>Performance-wise, you\'re more likely to get inefficiency from unoptimized queries than from the "wrong" choice of .NET construct.  At least, that\'s been my experience.</p>\n'}, {'answer_id': 2264, 'author': 'Shawn', 'author_id': 26, 'author_profile': 'https://Stackoverflow.com/users/26', 'pm_score': 3, 'selected': False, 'text': '<p>One feature of the DataSet is that if you can call multiple select statements in your stored procedures, the DataSet will have one DataTable for each.</p>\n'}, {'answer_id': 61082, 'author': 'tbreffni', 'author_id': 637, 'author_profile': 'https://Stackoverflow.com/users/637', 'pm_score': 2, 'selected': False, 'text': '<p>There are some optimizations you can use when filling a DataTable, such as calling BeginLoadData(), inserting the data, then calling EndLoadData().  This turns off some internal behavior within the DataTable, such as index maintenance, etc.  See <a href="https://blogs.objectsharp.com/post/2004/04/18/How-can-I-improve-the-loading-of-my-datasets.aspx" rel="nofollow noreferrer">this article</a> for further details.</p>\n'}, {'answer_id': 61086, 'author': 'Joshua Hudson', 'author_id': 6232, 'author_profile': 'https://Stackoverflow.com/users/6232', 'pm_score': 5, 'selected': False, 'text': '<p>One major difference is that DataSets can hold multiple tables and you can define relationships between those tables. </p>\n\n<p>If you are only returning a single result set though I would think a DataTable would be more optimized. I would think there has to be some overhead (granted small) to offer the functionality a DataSet does and keep track of multiple DataTables. </p>\n'}, {'answer_id': 40978093, 'author': 'MickeyfAgain_BeforeExitOfSO', 'author_id': 226555, 'author_profile': 'https://Stackoverflow.com/users/226555', 'pm_score': 1, 'selected': False, 'text': '<p>When you are only dealing with a single table anyway, the biggest practical difference I have found is that DataSet has a "HasChanges" method but DataTable does not. Both have a "GetChanges" however, so you can use that and test for null.</p>\n'}, {'answer_id': 57719183, 'author': 'Nischal Tyagi', 'author_id': 7156712, 'author_profile': 'https://Stackoverflow.com/users/7156712', 'pm_score': 0, 'selected': False, 'text': '<p>A DataTable object represents tabular data as an in-memory, tabular cache of rows, columns, and constraints. \nThe DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects.</p>\n'}]
['https://Stackoverflow.com/questions/2250', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/383/']