Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net SQLClient equivalent SQLClient equivalent of Oledb code

Posted on 2014-09-29
2
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

704 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