• 0

getSchema multiple tables


Question

I'm using .net 2 and the getschema function of the db connection to get database schema.

This is the code i'm using to get the schema. How do i get schema for

multiple tables at once using the same code

restrictions(0) = database

restrictions(1) = owner

restrictions(2) = table

newTable = dbConnection.GetSchema("columns", restrictions)

Link to comment
https://www.neowin.net/forum/topic/387153-getschema-multiple-tables/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

That is how you get multiple table schemas. You're getting the schema for the database you're connected to.

I think you're doing your restrictions incorrectly.

The first element is which catalog to use, the second is the owner(e.g. dbo), the third is the table name(e.g. Authors), and the fourth is table type. So, if you want all the tables that belong to dbo, you only need to specify that the second element of the restrictions array is "dbo".

This gets all the tables that belong to dbo.

  Dim connectionString As String = GetConnectionString()
  Dim restrictions(3) As String
  Using connection As New SqlConnection(connectionString)

    'Connect to the database, and then retrieve the 
    'schema information.
    connection.Open()
    restrictions(1) = "dbo"
    Dim table As DataTable = connection.GetSchema("Tables", _
       restrictions)

    ' Display the contents of the table.
    DisplayData(table)
    Console.WriteLine("Press any key to continue.")
    Console.ReadKey()
  End Using

If you omit the restrictions parameter altogether, you'll get all the tables, system and otherwise, for the current database.

  • 0
  weenur said:
That is how you get multiple table schemas. You're getting the schema for the database you're connected to.

I think you're doing your restrictions incorrectly.

The first element is which catalog to use, the second is the owner(e.g. dbo), the third is the table name(e.g. Authors), and the fourth is table type. So, if you want all the tables that belong to dbo, you only need to specify that the second element of the restrictions array is "dbo".

This gets all the tables that belong to dbo.

 ?Dim connectionString As String = GetConnectionString()
 ?Dim restrictions(3) As String
 ?Using connection As New SqlConnection(connectionString)

 ? ?'Connect to the database, and then retrieve the 
 ? ?'schema information.
 ? ?connection.Open()
 ? ?restrictions(1) = "dbo"
 ? ?Dim table As DataTable = connection.GetSchema("Tables", _
 ? ? ? restrictions)

 ? ?' Display the contents of the table.
 ? ?DisplayData(table)
 ? ?Console.WriteLine("Press any key to continue.")
 ? ?Console.ReadKey()
 ?End Using

If you omit the restrictions parameter altogether, you'll get all the tables, system and otherwise, for the current database.

586695150[/snapback]

But how would i get just two tables and not all of them or just one table

  • 0

OK, I see what you're getting at. You can't do it the way you want, apparently. The docs don't show a way to get multiple tables with the restrictions array.

What you could do is do a dynamic SQL query to select from the tables you want schema info from, and then use the DataTables(DataSet.Tables) you get back to get primary keys, or any other info.

What exactly are you trying to get from the schema?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Until they release 13.x, and then you'll be dumping on 7.x like you are 2.x. Sad but true...
    • EA shutting down Anthem servers soon, making the BioWare game unplayable by Pulasthi Ariyasinghe In early 2019, the RPG studio BioWare attempted a complete genre switch by releasing Anthem, a cooperative multiplayer game focused on seasonal content drops. In the end, the title failed to reach EA and fan expectations. Despite a revival attempt, BioWare quickly ended support for the title. Now, its servers are about to go down soon, and that means it's the last chance anyone has to play the online-only experience. In an official blog post regarding the game's future, it was revealed today that Anthem's online services will be shutting down on January 12, 2026. Starting today, all in-game premium currency purchases are also being halted, but any remaining credits held by players can still be used in the store until the shutdown date. "We have an important update to share regarding Anthem," said the post. "After careful consideration, we will be sunsetting Anthem on January 12, 2026. This means that the game will still be playable online for the next 180+ days." As there is no offline mode attached to the co-op game, it will not be playable by those who purchased it following the January 12, 2026 date. Interestingly, EA Play subscribers will lose access to the game ahead of that date, with it leaving the subscription service (also affecting Xbox Game Pass Ultimate and PC Game Pass) on August 15, 2025. The last time Anthem was mentioned by EA and BioWare was in 2021, which is when the companies announced the cancellation of the rework. The team working on this Anthem NEXT project was then moved to the developer of the Mass Effect and Dragon Age games. "We deeply appreciate your dedication, passion and support over the years and we’d like to thank you for that," added BioWare. EA has also confirmed that Anthem's shutdown is not affecting any jobs at BioWare. "No, the sunsetting of Anthem has not led to any layoffs," it said.
    • Apple has long had their own version; claiming they're "scanning for CSAM" as a justification for monitoring your entire device content, not just messages: https://www.youtube.com/watch?...W50ZXJuZXQgcHJpdmFjeQ%3D%3D An open-source Linux phone would be the real solution...
    • There are a lot of articles with worse content, way worse this one is what people with iPhones would like to know. I might even upgrade my 13Pro is this is true, even though I thought I can make it last another few years
  • Recent Achievements

    • Dedicated
      solidox earned a badge
      Dedicated
    • Week One Done
      solidox earned a badge
      Week One Done
    • Week One Done
      Devesh Beri earned a badge
      Week One Done
    • Week One Done
      956400 earned a badge
      Week One Done
    • First Post
      loose_observer earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      459
    2. 2
      ATLien_0
      161
    3. 3
      +FloatingFatMan
      149
    4. 4
      Nick H.
      66
    5. 5
      +thexfile
      61
  • Tell a friend

    Love Neowin? Tell a friend!