borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Access97 Variables in place of fields)Next Topic (ADO & MS Access) New Topic New Poll Post Reply
AndreaVB Forum : Database : Retrieving fieldnames
Poster Message
sunflower
Level: Guest


icon Retrieving fieldnames  Archived to Disk

Hi, I'm new to the world of ADO.  I'm trying to figure out, how to retrieve the fieldnames that exist in an MSAccess table without previously knowing what they are.  

Reason being, more could be added at a later date and I wanted to write code that was flexible enough to count the number of fields, and within a loop find the field names one by one, and then be able to access the data.  

Can anyone please offer some advice on how this can be done? Or if it's even possible?

Also, is there a way to create a new Table and assign new fieldnames?  

Thanks

06-08-2002 at 12:23 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: Retrieving fieldnames  Archived to Disk

' Field Names
    Dim i As Integer
    Dim ars As New ADODB.Recordset
    
    For i = 0 To ars.Fields.Count
        Debug.Print ars.Fields(i).Name
    Next

' Tables (although some Access versions and SQL differ)
    adodcCN.Execute "CREATE TABLE tablename (field1 as type, ..., fieldx as type)"

06-08-2002 at 08:17 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
ASHISH25
Level: Guest

icon Re: Retrieving fieldnames  Archived to Disk

' Find the Field Names
    Dim i As Integer
    Dim rs As New ADODB.Recordset
    
    For i = 0 To rs.Fields.Count
        Debug.Print rs.Fields(i).Name
    Next

' Tables creation
    cn.Execute "CREATE TABLE tablename (field1 as type, ..., fieldx as type)"




[Edited by ASHISH25 on 09-08-2002 at 10:27 AM GMT]

09-08-2002 at 10:27 AM
| Quote Reply
AndreaVB Forum : Database : Retrieving fieldnames
Previous Topic (Access97 Variables in place of fields)Next Topic (ADO & MS Access) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder