Obtener nombres de los campos de una tabla
Necesitaria obtener los nombres de los campos que tiene una tabla atraves de una consulta.
Por ejemplo si tenemos la tabla
Clientes
id
nombre
apellido
Quiero ejecutar una select que retorne 'id', 'nombre', 'apellidos'
Merci,
r a u l
Por ejemplo si tenemos la tabla
Clientes
id
nombre
apellido
Quiero ejecutar una select que retorne 'id', 'nombre', 'apellidos'
Merci,
r a u l
En este ejemplo utilizo ADODB para listar los campos de una tabla en SQL SERVER ...
Los campos obtenidos los cargo en un ListBox (list1) ...
\'++++++++++++
Dim cString AS String
dim oRSet AS RecordSet
cString = "SELECT * FROM dbo.syscolumns " & _
"WHERE id = object_id(N\'" & _
"TablaDeseada" & "\')"
Set oRSet = New Recordset
oRSet.Open cString, oConnection, adOpenStatic, adLockReadOnly
List1.Clear
If oRSet.EOF Then
List1.AddItem "No hubo campos ..."
Else
Do While Not oRSet.EOF
List1.AddItem oRSet.Fields(0)
oRSet.MoveNext
Loop
End If
oRSet.Close
SET ORSet = Nothing
\'+++++++++++++
Los campos obtenidos los cargo en un ListBox (list1) ...
\'++++++++++++
Dim cString AS String
dim oRSet AS RecordSet
cString = "SELECT * FROM dbo.syscolumns " & _
"WHERE id = object_id(N\'" & _
"TablaDeseada" & "\')"
Set oRSet = New Recordset
oRSet.Open cString, oConnection, adOpenStatic, adLockReadOnly
List1.Clear
If oRSet.EOF Then
List1.AddItem "No hubo campos ..."
Else
Do While Not oRSet.EOF
List1.AddItem oRSet.Fields(0)
oRSet.MoveNext
Loop
End If
oRSet.Close
SET ORSet = Nothing
\'+++++++++++++
