|
-
Jan 30th, 2001, 08:44 AM
#1
Thread Starter
Addicted Member
get all of the field names from a table in a SQL database and write them out to a VB form?
-
Jan 30th, 2001, 09:10 AM
#2
Fanatic Member
AngelinaM,
The following example lists the fields for a recordSet created from an Access database, but you should be able to apply it to a SQL database too. I just threw this code together, so minor changes may be needed to get all the fields. The most important point is that you use the ADODB.fields object to retrieve the field names.
Code:
Option Explicit
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim adofields As ADODB.Fields
Private Sub Command1_Click()
Dim x As Integer
Dim adofields As ADODB.Fields
Set adofields = rs.Fields
For x = 1 To (adofields.Count - 1)
Debug.Print adofields.Item(x).Name
Next x
End Sub
Private Sub Form_Load()
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;" & _
"Persist Security Info=False"
rs.Open "Select * from Customers", cnn, adOpenKeyset, adLockOptimistic
End Sub
-
Jan 30th, 2001, 09:57 AM
#3
Thread Starter
Addicted Member
PERFECT!
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
|