Results 1 to 4 of 4

Thread: Getting column names from access table

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    16

    Getting column names from access table

    hi,

    how can i get the column names of an access tables using vb ?

    sudha

  2. #2
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    DAO or ADO?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    16
    ADO

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Add a TreeView control (Microsoft Windows Comon Controls) and a Command Button:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim cn As ADODB.Connection
    3.     Dim rsTables As ADODB.Recordset
    4.     Dim rsFields As ADODB.Recordset
    5.     Dim strCnn As String
    6.     Dim nodParent As Node
    7.     Dim strNewTable As String
    8.     Dim strCurrentTable As String
    9.      
    10.     Set cn = New ADODB.Connection
    11.     strCnn = "Provider=microsoft.jet.oledb.4.0;Data Source=C:\NWIND.mdb"
    12.     cn.Open strCnn
    13.      
    14.     Set rsFields = cn.OpenSchema(adSchemaColumns)
    15.    
    16.     With TreeView1
    17.         .LineStyle = tvwRootLines
    18.         .Indentation = 250
    19.        
    20.         .Nodes.Add , , "root", "Northwind"
    21.         .Nodes.Add "root", tvwChild, "tables", "Tables"
    22.        
    23.         Do Until rsFields.EOF
    24.             strCurrentTable = rsFields!TABLE_NAME
    25.            
    26.             If strCurrentTable <> strNewTable Then
    27.                 strNewTable = strCurrentTable
    28.                 Set nodParent = .Nodes.Add("tables", tvwChild, strCurrentTable, strCurrentTable)
    29.             End If
    30.            
    31.             .Nodes.Add strCurrentTable, tvwChild, , rsFields!COLUMN_NAME
    32.  
    33.             rsFields.MoveNext
    34.         Loop
    35.     End With
    36.    
    37.     rsFields.Close
    38.    
    39.     cn.Close
    40. End Sub

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