Cita:
Iniciado por sabruchi
hola de nuevo!! al hacer una consulta a mysql, me muestra solo el primer campo no todos nose por que, ademas quisiera saber como agregar un mensaje de error si no encuentra ningun campo. gracias!!!
tengo el siguiente codigo en vb6
Public BD As ADODB.Connection
Public RecSQL As ADODB.Recordset
Private Sub Command1_Click()
On Error GoTo Ver
Set BD = New ADODB.Connection
BD.ConnectionString = "driver={MySQL ODBC 3.51 Driver};" & _
"Server=" & Text1 & ";" & _
"Port=" & Text2 & ";" & _
"Database=" & Text3 & ";" & _
"User=" & Text4 & ";" & _
"Password=" & Text5 & ";" & _
"Option=3;"
BD.Open
MsgBox "Conexión establecida!!!", vbExclamation, "Conexión"
Exit Sub
Ver:
MsgBox "Nº de error: " & Err.Number & " | " & Err.Description, vbCritical, "Control de errores"
Err.Clear
End Sub
Private Sub Command2_Click()
On Error GoTo Ver
Set RecBD = New ADODB.Recordset
RecBD.Open "select * from categories", BD, adOpenStatic, adLockOptimistic
Text6.Text = RecBD.Fields("id")
Text7.Text = RecBD.Fields("name")
Exit Sub
Ver:
MsgBox "Nº de error: " & Err.Number & " | " & Err.Description, vbCritical, "Control de errores"
Err.Clear
End Sub
Hola, aun así, a pesar de lo que te dice
David el Grande, solamente mostraría los datos del último registro en Text6 y Text7.
Si quieres mostrar todos los registros puedes utilizar un control DataGrid
Código:
Set RecBd = New ADODB.Recordset
RecBd.CursorLocation = adUseClient
RecBd.Open "select * from categories", BD, adOpenStatic, adLockOptimistic
If RecBd.RecordCount = 0 Then
MsgBox "No hay registros"
Exit Sub
End If
Set DataGrid1.DataSource = RecBd