Come leggere i nomi dei campi di una tabella senza conoscerli! VB6

November 9, 2011 at 1:19 pm Leave a comment

Ho una tabella, ma non so il nome dei suoi campi. Come fare?
Vado su google
Digito
adodb.recordset vb6 select get field names

spulcio i risultati
mi imbatto in

http://visualbasic.ittoolbox.com/groups/technical-functional/visualbasic-l/how-to-get-recordset-field-name-877933

tra i commenti trovo il codice

Sub ShowFieldsInfo()
Dim rs As New ADODB.Recordset

Dim i As Integer

‘Error handler
On Error GoTo ShowFields_Error

rs.Open “Select * from Routines;”, CurrentProject.Connection
‘get Field Info
For i = 0 To rs.Fields.Count – 1
‘Add textboxes and labels and position and unhide them here
‘lblLabel.Caption= rs.Fields(i).Name
‘Just for example
Debug.Print “Field ” & i & ” = ” & rs.Fields(i).Name & _
” Type = ” & FieldTypes(rs.Fields(i).Type) & _
” Defined Size =” & rs.Fields(i).DefinedSize
Next
‘Get Field data. Silly as you would only collect these one at a time for
display
Do While Not rs.BOF And Not rs.EOF
For i = 0 To rs.Fields.Count – 1
‘txtBox(i)= rs.Fields(i).Value
Debug.Print rs.Fields(i).Name & ” = ” & rs.Fields(i).Value
Next
rs.MoveNext
Loop
ShowFields_Exit:
‘All final code here
On Error Resume Next
rs.Close
Set rs = Nothing
On Error GoTo 0
Exit Sub

ShowFields_Error:
‘Report error and continue with cleanup for block
MsgBox “Error ” & Err.Number & _
” (” & Err.Description & “) in procedure ShowFields of Module
Module1″
Resume ShowFields_Exit

End Sub

Function FieldTypes(FieldType As Integer) As String
Select Case FieldType
Case AdArray: FieldTypes = “AdArray” ’0×2000
Case adBigInt: FieldTypes = “adBigInt” ’20
Case adBinary: FieldTypes = “adBinary” ’128
Case adBoolean: FieldTypes = “adBoolean” ’11
Case adBSTR: FieldTypes = “adBSTR” ’8
Case adChapter: FieldTypes = “adChapter” ’136
Case adChar: FieldTypes = “adChar” ’129
Case adCurrency: FieldTypes = “adCurrency” ’6
Case adDate: FieldTypes = “adDate” ’7
Case adDBDate: FieldTypes = “adDBDate” ’133
Case adDBTime: FieldTypes = “adDBTime” ’134
Case adDBTimeStamp: FieldTypes = “adDBTimeStamp” ’135
Case adDecimal: FieldTypes = “adDecimal” ’14
Case adDouble: FieldTypes = “adDouble” ’5
Case adEmpty: FieldTypes = “adEmpty” ’0
Case adError: FieldTypes = “adError” ’10
Case adFileTime: FieldTypes = “adFileTime” ’64
Case adGUID: FieldTypes = “adGUID” ’72
Case adIDispatch: FieldTypes = “adIDispatch” ’9
Case adInteger: FieldTypes = “adInteger” ’3
Case adIUnknown: FieldTypes = “adIUnknown” ’13
Case adLongVarBinary: FieldTypes = “adLongVarBinary” ’205
Case adLongVarChar: FieldTypes = “adLongVarChar” ’201
Case adLongVarWChar: FieldTypes = “adLongVarWChar” ’203
Case adNumeric: FieldTypes = “adNumeric” ’131
Case adPropVariant: FieldTypes = “adPropVariant” ’138
Case adSingle: FieldTypes = “adSingle” ’4
Case adSmallInt: FieldTypes = “adSmallInt” ’2
Case adTinyInt: FieldTypes = “adTinyInt” ’16
Case adUnsignedBigInt: FieldTypes = “adUnsignedBigInt” ’21
Case adUnsignedInt: FieldTypes = “adUnsignedInt” ’19
Case adUnsignedSmallInt: FieldTypes = “adUnsignedSmallInt” ’18
Case adUnsignedTinyInt: FieldTypes = “adUnsignedTinyInt” ’17
Case adUserDefined: FieldTypes = “adUserDefined” ’132
Case adVarBinary: FieldTypes = “adVarBinary” ’204
Case adVarChar: FieldTypes = “adVarChar” ’200
Case adVariant: FieldTypes = “adVariant” ’12
Case adVarNumeric: FieldTypes = “adVarNumeric” ’139
Case adVarWChar: FieldTypes = “adVarWChar” ’202
Case adWChar: FieldTypes = “adWChar” ’130
Case Else: FieldTypes = “Undefined”
End Select
End Function

Modifico la query, e funziona tutto!
Bene

Entry filed under: SQL, VB6. Tags: .

Accendere computer da remoto in c# sql backup & restore database to a different db

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

November 2011
M T W T F S S
« Oct    
 123456
78910111213
14151617181920
21222324252627
282930  

Most Recent Posts


Follow

Get every new post delivered to your Inbox.