ASP SQL Client version of code

Posted on 2012-08-31
Last Modified: 2012-09-03
Hi. How do I change the following code to work with SQL Client, instead of Oledb?

   Dim schemaTable As DataTable
        Dim i As Integer

        Dim cs As String = ConfigurationManager.ConnectionStrings("survey_conn").ConnectionString
        Dim cn As New OleDbConnection(cs)

            '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"})
Question by:murbro
    LVL 26

    Accepted Solution

    Hi Murbro,
    not sure if this is the sort of thing you are looking for:
      Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim schemaTable As System.Data.DataTable
        Dim i As Integer = 0
        Dim strSqlError As String = ""
        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("survey_conn").ConnectionString)
          '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.GetSchema("Restrictions")
          ' Display the contents of the table.
        Catch SQLexc As System.Data.SqlClient.SqlException
          strSqlError = "Operation Failed. Error Details are: " & SQLexc.ToString()
        End Try
      End Sub
      Private Sub DisplayData(ByVal table As System.Data.DataTable)
        For Each row As System.Data.DataRow In table.Rows
          For Each col As System.Data.DataColumn In table.Columns
            System.Diagnostics.Debug.WriteLine("{0} = {1}", col.ColumnName, row(col))
      End Sub

    Open in new window

    Working with the GetSchema Methods

    LVL 35

    Assisted Solution

    by:Robert Schutt
    I think there's an error on that MSDN page and as a consequence in the code Alan posted: GetSchema("Restrictions") is used in the VB example (returning foreign keys), whereas the correct GetSchema("Tables") is used in the C# example.

    I suspect they were thinking ahead to using a second argument to get only a certain tables.

    Author Closing Comment

    Thank you both

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    730 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

    18 Experts available now in Live!

    Get 1:1 Help Now