|
-
Feb 13th, 2004, 11:54 AM
#1
Thread Starter
pathfinder
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:
Imports MySys = System
Imports MyCol = System.Collections
Imports MyFrms = System.Windows.Forms
Imports MyOdbc = Microsoft.Data.Odbc
Imports MyApp = System.Windows.Forms.Application
Public Class Form1
Inherits System.Windows.Forms.Form
Dim mconnectionString As String = "DSN=CCFilemaker"
Dim mconn As New MyOdbc.OdbcConnection(mconnectionString)
Dim mSQL As String = "SELECT * FROM Parts WHERE ""Part Status"" = 'Obsolete'" '
Dim mCmd As New MyOdbc.OdbcCommand(mSQL)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Call LIST_TABLES()
Dim MyI As Integer
Dim MyOutStr As String
mCmd.Connection = mconn
mconn.Open()
Dim mReader As MyOdbc.OdbcDataReader = mCmd.ExecuteReader()
If mReader.Read = True Then
On Error GoTo herbie
For MyI = 0 To mReader.FieldCount - 1
MyOutStr = ""
If Not mReader.IsDBNull(MyI) Then
Select Case mReader.GetFieldType(MyI).Name
Case "DateTime"
MyOutStr = (mReader.GetDateTime(MyI).ToString())
Case "Double"
MyOutStr = (mReader.GetDouble(MyI).ToString())
Case Else
MyOutStr = (mReader.GetString(MyI).ToString())
End Select
End If
ListBox1.Items.Add(mReader.GetDataTypeName(MyI) & ":::" _
& mReader.GetName(MyI) & "=" & MyOutStr)
Next
End If
mReader.Close()
mconn.Close()
Exit Sub
herbie:
ListBox2.Items.Add(MyI & " " & mReader.GetDataTypeName(MyI) & " {" _
& mReader.GetFieldType(MyI).Name & "} :::" & mReader.GetName(MyI))
Resume Next
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:
Module UpgradeSupport
Friend RDOrdoEngine_definst As New RDO.rdoEngine()
End Module
and adding a reference to the com object: Microsoft Remote Data
Object 2.0
I've built the following code:
VB Code:
Private Sub LIST_TABLES()
Dim Cn As New RDO.rdoConnection()
Dim MyI As Integer
Dim En As RDO.rdoEnvironment
Dim Conn As String
En = RDOrdoEngine_definst.rdoEnvironments(0)
Conn = "DSN=CCFilemaker"
Cn = En.OpenConnection(dsName:="", Prompt:=RDO.PromptConstants.rdDriverNoPrompt, _
Connect:=Conn)
While Cn.StillConnecting = True
Me.Text = CStr(MyI)
MyI = MyI + 1
System.Windows.Forms.Application.DoEvents()
End While
ComboBox1.Items.Clear()
For MyI = 0 To Cn.rdoTables.Count - 1
ComboBox1.Items.Add(Cn.rdoTables(MyI).Name)
Next MyI
ComboBox1.SelectedIndex = 0
Cn.Close()
En.Close()
Cn = Nothing
En = Nothing
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.
-
Feb 13th, 2004, 10:07 PM
#2
Thread Starter
pathfinder
Impossible?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|