Elegir item de unCombobox
Publicado por Joel (1 intervención) el 18/02/2010 18:15:27
Hola a todos, necesito ayuda para solucionar este problema, tengo un boton conectado a un bd de sql server, al dar click se conecta y muestra solo el campo de los nombres en un combobox, al seleccionar el primer nombre me muestra todos los datos del nombre seleccionado en los label's ( 1,2,3,4,5,6,7,8,9,10) pero al dar click en otro nombre, no cambia la infomarcion de los label's, me sigue mostrando la informaciñon del primer nombre seleccionado, ¿Cómo puedo solucionar esto :S ? , trabajo en visual basic 6, y este es el código que tengo.
De antemano muchas gracias... :)
-----------------------------------------------------------------------------------------------------------------------------
Declaraciones generales
Option Explicit
Private cnn As ADODB.Connection
Private rst As ADODB.Recordset
Dim i As Integer
Dim rs As ADODB.Recordset
-----------------------------------------------------------------------------------------------------------------------------
Código del botón consultar a la bd de sql server
Private Sub Consultar_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = "Provider=SQLOLEDB; " & _
"Initial Catalog=Prueba; " & _
"Data Source=(local); " & _
"integrated security=SSPI; persist security info=True;"
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.Open "Select * from Jugadores"
End With
Do Until rs.EOF
cboRegistro.AddItem rs!Main
rs.MoveNext
Loop
End Sub
Al parecer aqui no tengo problemas con este botón por que funcioná como quiero.
-----------------------------------------------------------------------------------------------------------------------------
Este es el código del combobox, es en donde tengo problemas :S
cboRegistro = combobox, evento click
Private Sub cboRegistro_Click()
Set cnn = Nothing
Set rst = Nothing
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.Open "Provider=SQLOLEDB; " & _
"Initial Catalog=Prueba; " & _
"Data Source=(local); " & _
"integrated security=SSPI; persist security info=True;"
rst.Open "SELECT * FROM Jugadores", cnn, adOpenDynamic, adLockOptimistic
rst.MoveFirst
Label1.Caption = rst!Main
Label2.Caption = rst!Rango
Label3.Caption = rst!NombreRan
Label4.Caption = rst!Nivel
Label5.Caption = rst!Job
Label6.Caption = rst!Nombrer
Label7.Caption = rst!Edad
Label8.Caption = rst!Estado
Label9.Caption = rst!Lada
Label10.Caption = rst!Teléfono
End Sub
De antemano muchas gracias... :)
-----------------------------------------------------------------------------------------------------------------------------
Declaraciones generales
Option Explicit
Private cnn As ADODB.Connection
Private rst As ADODB.Recordset
Dim i As Integer
Dim rs As ADODB.Recordset
-----------------------------------------------------------------------------------------------------------------------------
Código del botón consultar a la bd de sql server
Private Sub Consultar_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = "Provider=SQLOLEDB; " & _
"Initial Catalog=Prueba; " & _
"Data Source=(local); " & _
"integrated security=SSPI; persist security info=True;"
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.Open "Select * from Jugadores"
End With
Do Until rs.EOF
cboRegistro.AddItem rs!Main
rs.MoveNext
Loop
End Sub
Al parecer aqui no tengo problemas con este botón por que funcioná como quiero.
-----------------------------------------------------------------------------------------------------------------------------
Este es el código del combobox, es en donde tengo problemas :S
cboRegistro = combobox, evento click
Private Sub cboRegistro_Click()
Set cnn = Nothing
Set rst = Nothing
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.Open "Provider=SQLOLEDB; " & _
"Initial Catalog=Prueba; " & _
"Data Source=(local); " & _
"integrated security=SSPI; persist security info=True;"
rst.Open "SELECT * FROM Jugadores", cnn, adOpenDynamic, adLockOptimistic
rst.MoveFirst
Label1.Caption = rst!Main
Label2.Caption = rst!Rango
Label3.Caption = rst!NombreRan
Label4.Caption = rst!Nivel
Label5.Caption = rst!Job
Label6.Caption = rst!Nombrer
Label7.Caption = rst!Edad
Label8.Caption = rst!Estado
Label9.Caption = rst!Lada
Label10.Caption = rst!Teléfono
End Sub
Valora esta pregunta


0