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. Table Names Of a MS Access Database

Table Names Of a MS Access Database

Scheduled Pinned Locked Moved C#
databasewindows-adminhelp
3 Posts 3 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.
  • D Offline
    D Offline
    Daminda
    wrote on last edited by
    #1

    I Want to List the Table Names Of a MS Access Database Using ADO Connection. This is How I tried ADODB.Connection myConnection = new ADODB.ConnectionClass(); ADODB.Recordset rsTblNames = new ADODB.RecordsetClass(); if (optAccess.Checked) { ConnStr= "Provider=Microsoft.Jet.OLEDB.4.0;User ID=;Data Source="+ txtDbPath.Text +";Mode=ReadWrite;Extended Properties='';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"; myConnection.Open(ConnStr,"","",0); StrSql= "SELECT Name FROM MSysObjects WHERE Type = 1"; rsTblNames.Open(StrSql, myConnection, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockReadOnly,0); } But This returns a Error

    H S 2 Replies Last reply
    0
    • D Daminda

      I Want to List the Table Names Of a MS Access Database Using ADO Connection. This is How I tried ADODB.Connection myConnection = new ADODB.ConnectionClass(); ADODB.Recordset rsTblNames = new ADODB.RecordsetClass(); if (optAccess.Checked) { ConnStr= "Provider=Microsoft.Jet.OLEDB.4.0;User ID=;Data Source="+ txtDbPath.Text +";Mode=ReadWrite;Extended Properties='';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"; myConnection.Open(ConnStr,"","",0); StrSql= "SELECT Name FROM MSysObjects WHERE Type = 1"; rsTblNames.Open(StrSql, myConnection, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockReadOnly,0); } But This returns a Error

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

      Why don't you tell us what that error reads? :doh: Besides, why are you using ADO.NET? It's much faster and for what you need can accomplish the same things. Your connection string doesn't change (although you could drop most of those options since they are mostly defaults and other unnecessary properties), nor does your SQL statement, just the code itself. This is, after all, the C# forum - a language targeting the CLR - so writing .NET applications and libraries is what this is about:

      OleDbConnection conn = new OleDbConnection(string.Format(
      "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Mode=ReadWrite",
      txtDbPath.Text));
      OleDbCommand cmd = conn.CreateCommand();
      cmd.CommandText = "SELECT Name FROM MSysObjects WHERE Type = 1";
      OleDbDataReader reader = null;
      try
      {
      conn.Open();
      reader = cmd.ExecuteReader();
      while (reader.Read())
      {
      Console.WriteLine(reader.GetString(0));
      }
      }
      catch (Exception e)
      {
      // Providing something like this in your message would've helped us
      // determine what the problem was!
      Console.Error.WriteLine("An error occured: {0}", e.Message);
      }
      finally
      {
      if (reader != null) reader.Close();
      conn.Close();
      }

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      • D Daminda

        I Want to List the Table Names Of a MS Access Database Using ADO Connection. This is How I tried ADODB.Connection myConnection = new ADODB.ConnectionClass(); ADODB.Recordset rsTblNames = new ADODB.RecordsetClass(); if (optAccess.Checked) { ConnStr= "Provider=Microsoft.Jet.OLEDB.4.0;User ID=;Data Source="+ txtDbPath.Text +";Mode=ReadWrite;Extended Properties='';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"; myConnection.Open(ConnStr,"","",0); StrSql= "SELECT Name FROM MSysObjects WHERE Type = 1"; rsTblNames.Open(StrSql, myConnection, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockReadOnly,0); } But This returns a Error

        S Offline
        S Offline
        Spanky3
        wrote on last edited by
        #3

        To get a list of table names: code:-------------------------------------------------------------------------------- SELECT Name FROM MSysObjects WHERE Type = 1; -------------------------------------------------------------------------------- To get list of query names: code:-------------------------------------------------------------------------------- SELECT Name FROM MSysObjects WHERE Type = 5; -------------------------------------------------------------------------------- additional information: code:-------------------------------------------------------------------------------- To get list of Forms: SELECT Name FROM MsysObjects WHERE Type =-32768; To get list of Reports: SELECT Name FROM MsysObjects WHERE Type = -32764; To get list of Modules: SELECT Name FROM MsysObjects WHERE Type = -32761; To get list of Macros: SELECT Name FROM MsysObjects WHERE Type = -32766;

        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