Results 1 to 2 of 2

Thread: How, Using ODBC, Return All Table Names?

  1. #1

    Thread Starter
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    How, Using ODBC, Return All Table Names?

    I'm trying to develop, useing ODBC, an app to read my companies
    FileMaker Database.

    Now, it seems to be easy to return search results with SQL when
    you "Know" the table names, but I want to programically return
    the table names consistent with ODBC.

    Here is a snippit of some development code to connect to FM and
    return some data:

    VB Code:
    1. Imports MySys = System
    2. Imports MyCol = System.Collections
    3. Imports MyFrms = System.Windows.Forms
    4.  
    5. Imports MyOdbc = Microsoft.Data.Odbc
    6. Imports MyApp = System.Windows.Forms.Application
    7.  
    8. Public Class Form1
    9.     Inherits System.Windows.Forms.Form
    10.     Dim mconnectionString As String = "DSN=CCFilemaker"
    11.     Dim mconn As New MyOdbc.OdbcConnection(mconnectionString)
    12.     Dim mSQL As String = "SELECT * FROM Parts WHERE ""Part Status"" = 'Obsolete'" '
    13.     Dim mCmd As New MyOdbc.OdbcCommand(mSQL)
    14.  
    15. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    16. Handles MyBase.Load
    17.         Call LIST_TABLES()
    18.         Dim MyI As Integer
    19.         Dim MyOutStr As String
    20.         mCmd.Connection = mconn
    21.         mconn.Open()
    22.         Dim mReader As MyOdbc.OdbcDataReader = mCmd.ExecuteReader()
    23.         If mReader.Read = True Then
    24.             On Error GoTo herbie
    25.             For MyI = 0 To mReader.FieldCount - 1
    26.                 MyOutStr = ""
    27.                 If Not mReader.IsDBNull(MyI) Then
    28.                     Select Case mReader.GetFieldType(MyI).Name
    29.                         Case "DateTime"
    30.                             MyOutStr = (mReader.GetDateTime(MyI).ToString())
    31.                         Case "Double"
    32.                             MyOutStr = (mReader.GetDouble(MyI).ToString())
    33.                         Case Else
    34.                             MyOutStr = (mReader.GetString(MyI).ToString())
    35.                     End Select
    36.                 End If
    37.                 ListBox1.Items.Add(mReader.GetDataTypeName(MyI) & ":::" _
    38. & mReader.GetName(MyI) & "=" & MyOutStr)
    39.             Next
    40.         End If
    41.         mReader.Close()
    42.         mconn.Close()
    43.         Exit Sub
    44. herbie:
    45.         ListBox2.Items.Add(MyI & " " & mReader.GetDataTypeName(MyI) & " {" _
    46. & mReader.GetFieldType(MyI).Name & "} :::" & mReader.GetName(MyI))
    47.         Resume Next
    48.     End Sub

    Now, I have yet to show you my code for the Call LIST_TABLES().
    I'll be getting to that.

    The above is nice and straight forward, and ODBC seems to be
    pretty simple. But for the life of me, as a VBNet n00b, I can't
    figure out how to use it to return the available table names.

    Now, I created a VB6 app, useing RDO, which does that without
    any problem. Opening it with VBNet, I've got some working code.

    Adding a module with the following code:
    VB Code:
    1. Module UpgradeSupport
    2.     Friend RDOrdoEngine_definst As New RDO.rdoEngine()
    3. End Module

    and adding a reference to the com object: Microsoft Remote Data
    Object 2.0

    I've built the following code:
    VB Code:
    1. Private Sub LIST_TABLES()
    2.         Dim Cn As New RDO.rdoConnection()
    3.         Dim MyI As Integer
    4.         Dim En As RDO.rdoEnvironment
    5.         Dim Conn As String
    6.         En = RDOrdoEngine_definst.rdoEnvironments(0)
    7.         Conn = "DSN=CCFilemaker"
    8.         Cn = En.OpenConnection(dsName:="", Prompt:=RDO.PromptConstants.rdDriverNoPrompt, _
    9. Connect:=Conn)
    10.         While Cn.StillConnecting = True
    11.             Me.Text = CStr(MyI)
    12.             MyI = MyI + 1
    13.             System.Windows.Forms.Application.DoEvents()
    14.         End While
    15.         ComboBox1.Items.Clear()
    16.         For MyI = 0 To Cn.rdoTables.Count - 1
    17.             ComboBox1.Items.Add(Cn.rdoTables(MyI).Name)
    18.         Next MyI
    19.         ComboBox1.SelectedIndex = 0
    20.         Cn.Close()
    21.         En.Close()
    22.         Cn = Nothing
    23.         En = Nothing
    24.     End Sub

    It works great, No Problem!

    But It seems to me that there must be an ODBC way, where I
    don't have to use the RDO.

    Anybody have any suggestions? I know, if it works, why
    complain, but it just doesn't feel right.


  2. #2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width