<p>Is there an easy way to read an entire Access file (.mdb) into a DataSet in .NET (specifically C# or VB)?</p>

<p>Or at least to get a list of tables from an access file so that I can loop through it and add them one at a time into a DataSet?</p>

[{'answer_id': 46490, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 2, 'selected': False, 'text': '<p>You should be able to access it using an <a href="http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.aspx" rel="nofollow noreferrer">OleDbConnection</a>.</p>\n<p><a href="http://www.csharphelp.com/archives/archive70.html" rel="nofollow noreferrer">Heres</a> a tut on DB access using it for MS Access files.</p>\n<p>In terms of getting the table names, back in my VB6 days I always used ADOX, not sure how they do this in .NET now.. Although I know there is a system table in the access file - wanna say &quot;mso...&quot;. I google!</p>\n<h3>EDIT</h3>\n<p>Ah ha! <em>msysobjects</em> !! xD</p>\n'}, {'answer_id': 46492, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/ms971485.aspx" rel="nofollow noreferrer">MSDN</a> has an article on how to use ADO.NET to connect and edit records in an Access database. Once your OleDB connection is made, you can easily create your DataReader/DataAdapter and process as needed.</p>\n\n<p>EDIT: Gah! Curse you Rob and your god-like typing abilities!!! 8^D</p>\n'}, {'answer_id': 46526, 'author': 'jerhinesmith', 'author_id': 1108, 'author_profile': 'https://Stackoverflow.com/users/1108', 'pm_score': 4, 'selected': True, 'text': '<p>Thanks for the suggestions.  I was able to use those samples to put together this code, which seems to achieve what I\'m looking for.</p>\n\n<pre><code>Using cn = New OleDbConnection(connectionstring)\n    cn.Open()\n    Dim ds As DataSet = new DataSet()\n\n    Dim Schema As DataTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})\n    For i As Integer = 0 To Schema.Rows.Count - 1\n        Dim dt As DataTable = New DataTable(Schema.Rows(i)!TABLE_NAME.ToString())\n\n        Using adapter = New OleDbDataAdapter("SELECT * FROM " + Schema.Rows(i)!TABLE_NAME.ToString(), cn)\n            adapter.Fill(dt)\n        End Using\n\n        ds.Tables.Add(dt)\n    Next i\nEnd Using\n</code></pre>\n'}, {'answer_id': 46531, 'author': 'Fionnuala', 'author_id': 2548, 'author_profile': 'https://Stackoverflow.com/users/2548', 'pm_score': 0, 'selected': False, 'text': '<p>There is a discussion on this point in <a href="http://forum.lessthandot.com/viewtopic.php?f=95&amp;t=1262" rel="nofollow noreferrer">Less Than Dot</a>. Here is one example of code from the discussion.</p>\n\n<pre><code>   public DataTable GetColumns(string tableName)\n    {\n        string[] restrictions = new string[4];\n        restrictions[2] = tableName;\n\n        _connDb.Open();\n\n        DataTable mDT = _connDb.GetSchema("Columns", restrictions);\n\n        _connDb.Close();\n\n        return mDT;\n    }\n</code></pre>\n'}, {'answer_id': 67510, 'author': 'David-W-Fenton', 'author_id': 9787, 'author_profile': 'https://Stackoverflow.com/users/9787', 'pm_score': 0, 'selected': False, 'text': '<p>Your original question as worded is nonsense:</p>\n\n<blockquote>\n  <p>Is there an easy way to read an entire Access file (.mdb) into...</p>\n</blockquote>\n\n<p>You certainly <em>don\'t</em> want the entire contents of the MDB file. What you want is the contents of your data tables that are stored in the MDB. Keep in mind that you don\'t want the contents of the system tables, either.</p>\n\n<p>The key point:</p>\n\n<p>You\'re asking about JET, not about ACCESS.</p>\n\n<p>Jet is the database engine that ships as the default data store of Access (and in which Access\'s own objects are stored). But "Access" means something much more than just the data tables.</p>\n\n<p>Whenever you ask a question and confuse Access and Jet, you will likely get at least some unuseful answers.</p>\n\n<p>And you\'ll get scolded by the likes of me, because developers really should know better than to obfuscate crucial distinctions.</p>\n'}]
['https://Stackoverflow.com/questions/46482', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1108/']