Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Asignación de datos al Datagrid

Estas en el tema de Asignación de datos al Datagrid en el foro de Visual Basic clásico en Foros del Web. Hola foreros mi pregunta es como puedo asignarle los datos al datagrid sin tener que hacerlo de manera automatica.... bueno con el codigo me explico ...
  #1 (permalink)  
Antiguo 10/03/2006, 20:23
Avatar de juanutcm
Usuario no validado
 
Fecha de Ingreso: marzo-2005
Mensajes: 194
Antigüedad: 19 años, 1 mes
Puntos: 0
Exclamación Asignación de datos al Datagrid

Hola foreros mi pregunta es como puedo asignarle los datos al datagrid sin tener que hacerlo de manera automatica.... bueno con el codigo me explico mejor:


Sub doConexion()
Dim rstUsuarios As ADODB.Recordset
Dim strCnn As String
' Abre la tabla usuarios
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Archivos de programa\SoftwareSCC\Datos\bdSCC.mdb;Persist Security Info=FalseProvider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Archivos de programa\SoftwareSCC\Datos\bdSCC.mdb;Persist Security Info=False"
Set rstUsuarios = New ADODB.Recordset
rstUsuarios.CursorLocation = adUseClient
rstUsuarios.CursorType = adOpenDynamic
rstUsuarios.LockType = adLockBatchOptimistic
rstUsuarios.Open "SELECT Nombre,ApellidoPaterno,ApellidoMaterno,Calle,Numer o,Telefono,NombreUsuario FROM Usuario " & _
"", strCnn, , , adCmdText
With DataGrid1
.Columns(0).DataField = rstUsuarios.Fields.Item(Nombre)
End With
End Sub

Intente hacerlo asi pero no me funciona alguna ayudita me serviria.....
  #2 (permalink)  
Antiguo 10/03/2006, 21:04
Avatar de juanutcm
Usuario no validado
 
Fecha de Ingreso: marzo-2005
Mensajes: 194
Antigüedad: 19 años, 1 mes
Puntos: 0
bueno ahora lo he conseguido con un listview pero aun me fallan algunos aspectos pero aqui paso el codigo para quien este interesado en el tema...

Dim rstUsuarios As ADODB.Recordset
Dim strCnn As String
' Abre la tabla usuarios
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Archivos de programa\SoftwareSCC\Datos\bdSCC.mdb;Persist Security Info=FalseProvider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Archivos de programa\SoftwareSCC\Datos\bdSCC.mdb;Persist Security Info=False"
Set rstUsuarios = New ADODB.Recordset
rstUsuarios.CursorLocation = adUseClient
rstUsuarios.CursorType = adOpenDynamic
rstUsuarios.LockType = adLockBatchOptimistic
rstUsuarios.Open "SELECT Nombre,ApellidoPaterno,ApellidoMaterno,Calle,Numer o,Telefono,NombreUsuario FROM Usuario " & _
"", strCnn, , , adCmdText
With rstUsuarios
If (.BOF And .BOF) Then
MsgBox "Base de datos vacia", vbInformation + vbOKOnly, "SCC" 'Enviar mensaje de error
Else
ListView1.ListItems.Clear
.MoveFirst
Do While Not .EOF
tli = ListView1.ListItems.Add(, .Fields("Nombre") & "")
tli = ListView1.ListItems.Add(, , .Fields("Calle") & "")
tli = ListView1.ListItems.Add(, , .Fields("Numero") & "")
.MoveNext
Loop
End If
ListView1.GridLines = True
End With
  #3 (permalink)  
Antiguo 10/03/2006, 22:38
Avatar de juanutcm
Usuario no validado
 
Fecha de Ingreso: marzo-2005
Mensajes: 194
Antigüedad: 19 años, 1 mes
Puntos: 0
Ya consegui mostrarlos como queria ahora solo me falta eliminar el registro seleccionado en el listview se elimine en la base de datos.... pude eliminar del listview pero no se como hacerlo para borrarlo de la base de datos.... pongo el codigo para ayuda...


AQUI SELECCIONO Y MUESTRO LOS REGISTROS

Dim rstUsuarios As ADODB.Recordset
Dim strCnn As String
' Abre la tabla usuarios
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Archivos de programa\SoftwareSCC\Datos\bdSCC.mdb;Persist Security Info=FalseProvider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Archivos de programa\SoftwareSCC\Datos\bdSCC.mdb;Persist Security Info=False"
Set rstUsuarios = New ADODB.Recordset
rstUsuarios.CursorLocation = adUseClient
rstUsuarios.CursorType = adOpenDynamic
rstUsuarios.LockType = adLockBatchOptimistic
rstUsuarios.Open "SELECT Nombre,ApellidoPaterno,ApellidoMaterno,Calle,Numer o,Telefono,NombreUsuario FROM Usuario " & _
"", strCnn, , , adCmdText
With rstUsuarios
' Nombre1 = .Fields(Nombre & ApellidoPaterno & ApellidoMaterno)
If (.BOF And .BOF) Then
MsgBox "Base de datos vacia", vbInformation + vbOKOnly, "SCC" 'Enviar mensaje de error
Else
ListView1.ListItems.Clear
.MoveFirst
Do While Not .EOF
Set tli = ListView1.ListItems.Add(, , .Fields("Nombre"))
tli.SubItems(1) = .Fields("ApellidoPaterno")
tli.SubItems(2) = .Fields("ApellidoMaterno")
.MoveNext
Loop
End If
End With


Y AQUI ELIMINO DEL LISTVIEW


Private Sub cmdBaja_Click()
Dim intConfirmacion As Integer
For i = ListView1.ListItems.Count To 1 Step -1
If ListView1.ListItems(i).Selected Then
intConfirmacion = MsgBox("Estas a punto de eliminar un registro de la base de datos, ¿deseas continuar?", _
vbCritical + vbYesNo, "SCC")
If intConfirmacion = vbYes Then
ListView1.ListItems.Remove i
Else
End If
End If
Next i
End Sub


COMO LE HAGO PARA ELIMINARLO DE LA BD......
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:09.