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. Database & SysAdmin
  3. Database
  4. Access: SQL export [SOLVED]

Access: SQL export [SOLVED]

Scheduled Pinned Locked Moved Database
databasecsharpphpcomtools
8 Posts 5 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.
  • L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #1

    For an existing Access database holding around 100 queries, I'm looking for a comfortable way to export the actual SQL statements that represent those queries; ideally I'd like some (C#) code that generates a DataTable, with columns queryName and SqlStatement. Alternatively, a command or script that tells Access to create a text file holding such information. Or some magical SQL snippet that creates a new table in the database itself. To be perfectly clear, I need the SQL statements, not the results of the queries themselves. And I'll need to run it a couple of times in the next few months, so I don't plan on doing it manually, one by one! :)

    Luc Pattyn [My Articles] Nil Volentibus Arduum

    modified on Wednesday, August 24, 2011 10:12 AM

    G D L 3 Replies Last reply
    0
    • L Luc Pattyn

      For an existing Access database holding around 100 queries, I'm looking for a comfortable way to export the actual SQL statements that represent those queries; ideally I'd like some (C#) code that generates a DataTable, with columns queryName and SqlStatement. Alternatively, a command or script that tells Access to create a text file holding such information. Or some magical SQL snippet that creates a new table in the database itself. To be perfectly clear, I need the SQL statements, not the results of the queries themselves. And I'll need to run it a couple of times in the next few months, so I don't plan on doing it manually, one by one! :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      modified on Wednesday, August 24, 2011 10:12 AM

      G Offline
      G Offline
      Geoff Williams
      wrote on last edited by
      #2

      This[^] is not exactly what you requested, but might prove a useful starting point.

      L 1 Reply Last reply
      0
      • L Luc Pattyn

        For an existing Access database holding around 100 queries, I'm looking for a comfortable way to export the actual SQL statements that represent those queries; ideally I'd like some (C#) code that generates a DataTable, with columns queryName and SqlStatement. Alternatively, a command or script that tells Access to create a text file holding such information. Or some magical SQL snippet that creates a new table in the database itself. To be perfectly clear, I need the SQL statements, not the results of the queries themselves. And I'll need to run it a couple of times in the next few months, so I don't plan on doing it manually, one by one! :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        modified on Wednesday, August 24, 2011 10:12 AM

        D Offline
        D Offline
        David Mujica
        wrote on last edited by
        #3

        This article may help you out ... http://www.databasejournal.com/features/msaccess/article.php/3528491/Use-System-Tables-to-Manage-Objects.htm[^] It talks about the Sys Tables inside MS-Access. Good luck. :thumbsup:

        L 1 Reply Last reply
        0
        • L Luc Pattyn

          For an existing Access database holding around 100 queries, I'm looking for a comfortable way to export the actual SQL statements that represent those queries; ideally I'd like some (C#) code that generates a DataTable, with columns queryName and SqlStatement. Alternatively, a command or script that tells Access to create a text file holding such information. Or some magical SQL snippet that creates a new table in the database itself. To be perfectly clear, I need the SQL statements, not the results of the queries themselves. And I'll need to run it a couple of times in the next few months, so I don't plan on doing it manually, one by one! :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          modified on Wednesday, August 24, 2011 10:12 AM

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Problem solved, using "good" old DAO from C# isn't that hard after all, and all that was required is this:

          public override void GetQueries() {
          DAO._DBEngine dbEng=new DAO.DBEngineClass();
          DAO.Workspace ws = dbEng.CreateWorkspace("", "admin", "", DAO.WorkspaceTypeEnum.dbUseJet);
          DAO.Database db = ws.OpenDatabase(File, false, false, "");
          foreach(DAO.QueryDef q in db.QueryDefs) {
          env.log(0, q.Name+" = "+q.SQL);
          }
          }

          Thanks for all the input! :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          S L 2 Replies Last reply
          0
          • G Geoff Williams

            This[^] is not exactly what you requested, but might prove a useful starting point.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Thanks a lot, I got it working right away. :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            1 Reply Last reply
            0
            • D David Mujica

              This article may help you out ... http://www.databasejournal.com/features/msaccess/article.php/3528491/Use-System-Tables-to-Manage-Objects.htm[^] It talks about the Sys Tables inside MS-Access. Good luck. :thumbsup:

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Thanks for the quick response. I managed to solve my little problem with the first reply I got. :)

              Luc Pattyn [My Articles] Nil Volentibus Arduum

              1 Reply Last reply
              0
              • L Luc Pattyn

                Problem solved, using "good" old DAO from C# isn't that hard after all, and all that was required is this:

                public override void GetQueries() {
                DAO._DBEngine dbEng=new DAO.DBEngineClass();
                DAO.Workspace ws = dbEng.CreateWorkspace("", "admin", "", DAO.WorkspaceTypeEnum.dbUseJet);
                DAO.Database db = ws.OpenDatabase(File, false, false, "");
                foreach(DAO.QueryDef q in db.QueryDefs) {
                env.log(0, q.Name+" = "+q.SQL);
                }
                }

                Thanks for all the input! :)

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                S Offline
                S Offline
                S Douglas
                wrote on last edited by
                #7

                Luc Pattyn wrote:

                DAO

                WOW! That brings back memorys...Not entirly good ones but still :)


                Common sense is admitting there is cause and effect and that you can exert some control over what you understand.

                1 Reply Last reply
                0
                • L Luc Pattyn

                  Problem solved, using "good" old DAO from C# isn't that hard after all, and all that was required is this:

                  public override void GetQueries() {
                  DAO._DBEngine dbEng=new DAO.DBEngineClass();
                  DAO.Workspace ws = dbEng.CreateWorkspace("", "admin", "", DAO.WorkspaceTypeEnum.dbUseJet);
                  DAO.Database db = ws.OpenDatabase(File, false, false, "");
                  foreach(DAO.QueryDef q in db.QueryDefs) {
                  env.log(0, q.Name+" = "+q.SQL);
                  }
                  }

                  Thanks for all the input! :)

                  Luc Pattyn [My Articles] Nil Volentibus Arduum

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Luc Pattyn wrote:

                  DAO

                  Ahhhhh!!!! Good old DAO :-)

                  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