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. how to get names and count of tables

how to get names and count of tables

Scheduled Pinned Locked Moved C#
databasetutorialquestion
5 Posts 4 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.
  • P Offline
    P Offline
    phowarso
    wrote on last edited by
    #1

    how to get names and count of tables in a database from sqlserver and MSAccess? could u tell me pls?

    P A 2 Replies Last reply
    0
    • P phowarso

      how to get names and count of tables in a database from sqlserver and MSAccess? could u tell me pls?

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      While some database systems provide that functionality in various ways, with any database system that provides an ADO.net provider, the Connection derives (or should derive*) from System.Data.Common.DbConnection, which has a GetSchema method which returns a DataTable with that information. So I have been using the following:

      System.Data.Common.DbConnection con =
      this.command.Connection as System.Data.Common.DbConnection ;

      if ( con != null )
      {
      System.Data.DataTable temp = con.GetSchema
      (
      "TABLES"
      ) ;

      temp.DefaultView.RowFilter = "TABLE_TYPE='TABLE' OR TABLE_TYPE='BASE TABLE'" ;
      temp.DefaultView.Sort = "TABLE_NAME" ;

      This is good enough for SQL Server, Access, and Excel. But this is old code; a week or so ago I started using Oracle and MySql (and FireBird, just because) again and found that the tables provided by them are more different than I expected so I had to adapt. * I'm looking at you Cache. :mad:

      M 1 Reply Last reply
      0
      • P phowarso

        how to get names and count of tables in a database from sqlserver and MSAccess? could u tell me pls?

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        http://davidhayden.com/blog/dave/archive/2006/10/01/GetListOfTablesInMicrosoftAccessUsingGetSchema.aspx[^] ought to help you.

        1 Reply Last reply
        0
        • P PIEBALDconsult

          While some database systems provide that functionality in various ways, with any database system that provides an ADO.net provider, the Connection derives (or should derive*) from System.Data.Common.DbConnection, which has a GetSchema method which returns a DataTable with that information. So I have been using the following:

          System.Data.Common.DbConnection con =
          this.command.Connection as System.Data.Common.DbConnection ;

          if ( con != null )
          {
          System.Data.DataTable temp = con.GetSchema
          (
          "TABLES"
          ) ;

          temp.DefaultView.RowFilter = "TABLE_TYPE='TABLE' OR TABLE_TYPE='BASE TABLE'" ;
          temp.DefaultView.Sort = "TABLE_NAME" ;

          This is good enough for SQL Server, Access, and Excel. But this is old code; a week or so ago I started using Oracle and MySql (and FireBird, just because) again and found that the tables provided by them are more different than I expected so I had to adapt. * I'm looking at you Cache. :mad:

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          PIEBALDconsult wrote:

          a week or so ago I started using Oracle and MySql

          Poor bastard, you have my sincere sympathies.

          Never underestimate the power of human stupidity RAH

          P 1 Reply Last reply
          0
          • M Mycroft Holmes

            PIEBALDconsult wrote:

            a week or so ago I started using Oracle and MySql

            Poor bastard, you have my sincere sympathies.

            Never underestimate the power of human stupidity RAH

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Yes, thank you. Fortunately all I need to do is pull some data from them and make copies in SQL Server, but I still need to be sure that my data access library works with them.

            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