Skip to content

Instantly share code, notes, and snippets.

@facebookegypt
Created December 6, 2013 22:09
Show Gist options
  • Save facebookegypt/7832990 to your computer and use it in GitHub Desktop.
Save facebookegypt/7832990 to your computer and use it in GitHub Desktop.
AdsConnection.GetSchema vb.net
'AdsConnection.GetSchema
'How to retrieve Ads Data Dictionary Tables, Columns in a treeview control
Imports Advantage.Data.Provider
'Create VB 2010 Project (MyProject)
Public Class MyProject
Dim CN As New AdsConnection
Dim CMD As New AdsCommand
Public Sub GetAllTables(con As AdsConnection, TrV As TreeView)
Dim ATB As DataTable 'DataTable
Dim RootNode As TreeNode 'For Tables
Dim tableName As String 'For Tables Names
ATB = con.GetSchema("TABLES")
Dim I As Integer
'Place a treeview control (name: TV1) on the form
TrV.Nodes.Clear()
TrV.Nodes.Add(key:="Root", text:="Tables")
For I = 0 To ATB.Rows.Count - 1
tableName = CType(ATB.Rows(I)("TABLE_NAME"), String)
RootNode = TrV.Nodes.Add(key:="table", text:=tableName)
With CMD
.Connection = con
.CommandType = CommandType.Text
.CommandText = "SELECT * FROM [" & tableName & "]"
End With
Dim DR As AdsDataReader = CMD.ExecuteReader
DR.Read()
Dim COL As String
For I1 As Integer = 0 To DR.FieldCount - 1
COL = DR.GetName(I1).ToString
Dim Childnode As TreeNode = RootNode.Nodes.Add(key:="Column", text:=COL)
Next
DR.Close()
Next
End Sub
'Place a button on the Form (Name: Button1, text: Populate)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Open AdsConnection
If CN.State = ConnectionState.Open Then CN.Close()
Dim DAPath as String = ("D:\Project\MyProjectFolder\Bin\Debug\")
Dim UsrNm As String = "" 'Provide a Username if there is one, or leave it blank
CN.ConnectionString = ("Data Source=" & DAPath & ";" & _
"User ID=" & UsrNm & ";" & _
"Advantage Server Type=ADS_LOCAL_SERVER;")
CN.Open()
GetAllTables(CN,TV1)
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment