Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.net SQLClient equivalent SQLClient equivalent of Oledb code

Posted on 2014-09-29
2
Medium Priority
?
240 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:Murray Brown
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 40352285
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:Murray Brown
ID: 40352376
thanks very much
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

877 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