Solved

VB.net SQLClient equivalent SQLClient equivalent of Oledb code

Posted on 2014-09-29
2
227 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
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:murbro
ID: 40352376
thanks very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

16 Experts available now in Live!

Get 1:1 Help Now