Solved

VB.net SQLClient equivalent SQLClient equivalent of Oledb code

Posted on 2014-09-29
2
220 Views
Last Modified: 2014-09-30
Hi. What is the SQLClient equivalent of the following code be

    Sub GetTableNames()

        Dim schemaTable As DataTable
        Dim i As Integer

        Dim cs As String = Globals.ThisAddIn.oRIGHT.lblConnectionString.Text
        Dim cn As New OleDbConnection(cs)
        Try
            cn.Open()

            'Retrieve schema information about tables.
            'Because tables include tables, views, and other objects,
            'restrict to just TABLE in the Object array of restrictions.
            schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                          New Object() {Nothing, Nothing, Nothing, "TABLE"})

            'List the table name from each row in the schema table.
            Me.cmbTables.Items.Clear()
            Me.cmbTables.Items.Add("N/A")
            'Count = 0 'used to load arrays used for data types
            For i = 0 To schemaTable.Rows.Count - 1
                'Console.WriteLine(schemaTable.Rows(i)!TABLE_NAME.ToString)
                Me.cmbTables.Items.Add(schemaTable.Rows(i)!TABLE_NAME.ToString)
            Next i
            'Me.DropDownList_Table.SelectedIndex = 0

            'Explicitly close - don't wait on garbage collection.
            cn.Close()

            'Pause
            Console.ReadLine()
            cn = Nothing


        Catch
            'frmR.TopMost = False

            MsgBox("There was a problem getting table names! There may be a problem connecting to the online table." & Err.Description)
            'frmR.TopMost = True

        End Try
    End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
There is nothing that I know that is built in the SqlClient namespace itself.

But there are 2 different ways to access a SQL Server database schema. Unfortunately, I do not currently have code that use either of them and do not have time to write some code and test it.

You can simply run the following query: SELECT * FROM information_schema.tables, and read the value in the TABLE_NAME field.

If you would rather use an more object oriented approach, the Microsoft.SqlServer.Management.Smo namespace (you need to reference the Microsoft.SqlServer.Smo library to access it) can be used to get information about the structure of a database, such as the list of tables it contains.
0
 

Author Closing Comment

by:murbro
Comment Utility
thanks very much
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now