Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting table names from .mdb

Getting table names from .mdb

Scheduled Pinned Locked Moved C#
databasehelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benglish72
    wrote on last edited by
    #1

    Hi, I'm trying to find a way to get the names of tables in a .mdb file programmatically. The OleDBDataAdapter requires that you use an SQL select statement, but that's a bit hard if you don't yet know the table names in a file. Any help, tips? Thanks, Brian.

    H 1 Reply Last reply
    0
    • B benglish72

      Hi, I'm trying to find a way to get the names of tables in a .mdb file programmatically. The OleDBDataAdapter requires that you use an SQL select statement, but that's a bit hard if you don't yet know the table names in a file. Any help, tips? Thanks, Brian.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      This has been asked several times in this forum. To note, it's usually a good idea to try searching for previous threads in a forum like this. See my previous response at http://www.codeproject.com/script/comments/forums.asp?msg=776353&forumid=1649#xx776353xx[^] for a discussion of this. Simply, use a query like so:

      SELECT Name
      FROM MSysObjects
      WHERE Type = 1 AND NOT Name LIKE 'MSys%'

      Microsoft MVP, Visual C# My Articles

      B 1 Reply Last reply
      0
      • H Heath Stewart

        This has been asked several times in this forum. To note, it's usually a good idea to try searching for previous threads in a forum like this. See my previous response at http://www.codeproject.com/script/comments/forums.asp?msg=776353&forumid=1649#xx776353xx[^] for a discussion of this. Simply, use a query like so:

        SELECT Name
        FROM MSysObjects
        WHERE Type = 1 AND NOT Name LIKE 'MSys%'

        Microsoft MVP, Visual C# My Articles

        B Offline
        B Offline
        benglish72
        wrote on last edited by
        #3

        Hi, here's a code snippet of what I'm trying to do, but it throws an exception when I try to fill the dataset. I'm not familiar enough with .NET database stuff to know if this is the right way to go about it. Any ideas? Thanks. DataSet myDataSet = new DataSet(); string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ dataFile; string strAccessSelect = "SELECT Name FROM MSysObjects WHERE Type = 1 AND Name LIKE 'MSys%'"; try { OleDbDataAdapter myDataAdapter = new OleDbDataAdapter (strAccessSelect,strAccessConn); myDataAdapter.Fill(myDataSet,"MSysObjects"); DataTableCollection dta = myDataSet.Tables; Int32 iCount = dta.Count; for(Int32 i=0;i

        H 1 Reply Last reply
        0
        • B benglish72

          Hi, here's a code snippet of what I'm trying to do, but it throws an exception when I try to fill the dataset. I'm not familiar enough with .NET database stuff to know if this is the right way to go about it. Any ideas? Thanks. DataSet myDataSet = new DataSet(); string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ dataFile; string strAccessSelect = "SELECT Name FROM MSysObjects WHERE Type = 1 AND Name LIKE 'MSys%'"; try { OleDbDataAdapter myDataAdapter = new OleDbDataAdapter (strAccessSelect,strAccessConn); myDataAdapter.Fill(myDataSet,"MSysObjects"); DataTableCollection dta = myDataSet.Tables; Int32 iCount = dta.Count; for(Int32 i=0;i

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          First of all, you want WHERE Type = 1 AND **NOT** Name LIKE 'MSys%', as I wrote in my reply to your original post. Second of all, don't waste time and resources with a DataSet when you only need a single column anyway:

          using (OleDbConnection conn = new OleDbConnection(strAccessConn))
          {
          using (OleDbCommand cmd = conn.CreateCommand())
          {
          // Make sure to modify the WHERE clause
          cmd.CommandText = strAccessSelect;
           
          conn.Open();
          OleDbDataReader reader = cmd.ExecuteReader();
          while (reader.Read())
          cbTables.Items.Add(reader.GetString(0));
           
          conn.Close();
          }
          }

          This is much more efficient - using a forward-only data reader instead of creating a DataSet schema and filling it, which is good for disconnected data, but terribly inefficient for something like this.

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups