Ver Mensaje Individual
  #11 (permalink)  
Antiguo 07/07/2009, 11:41
Avatar de pyroCL
pyroCL
 
Fecha de Ingreso: marzo-2009
Ubicación: C#
Mensajes: 261
Antigüedad: 15 años, 10 meses
Puntos: 2
Respuesta: Pasar resultado de una columna a variables

Vé este código...

Clase Servicio...

Código VB.Net:
Ver original
  1. Public Class Servicio
  2.     Dim nombre As String
  3.     Dim horaInicio As String
  4.     Dim horaFin As String
  5.     Public Sub constructor(ByVal n As String, ByVal i As String, ByVal f As String)
  6.         nombre = n
  7.         horaInicio = i
  8.         horaFin = f
  9.     End Sub
  10.     Public Function getIni() As String
  11.         getIni = horaInicio
  12.     End Function
  13.     Public Function getfin() As String
  14.         getfin = horaFin
  15.     End Function
  16.     Public Function getNombre() As String
  17.         getNombre = nombre
  18.     End Function
  19. End Class


Ahora, desde la BD rescato todos los valores que estén en la tabla HA_SERVICES_H, los cuales son nombre, hora inicio y hora fin...
Cada uno de estos los guardo en una lista (en vez de listas pordrías usar variables string o cosas así, pero al hacer eso sólo tienes que tener un valor por variable), es decir debes dar una condición al SELECT, que puede ser WHERE Nombre='"nombre1"'


Código vb.net:
Ver original
  1. Dim servicio As New Servicio
  2.         SQL = "select * from HA_SERVICES_H order by INICIO"
  3.         'en el metodo conectar está el string de conexion a la base de datos
  4.         Comando.Connection = conectar()
  5.         Comando.CommandText = SQL
  6.         Dim lista As New Collection
  7.         Dim lista2 As New Collection
  8.         Dim lista3 As New Collection
  9.         rs = Comando.ExecuteReader()
  10.         While rs.Read
  11.             servicio.constructor(rs("SERVICIO"), rs("INICIO"), rs("FIN"))
  12.             lista.Add(servicio.getNombre)
  13.             lista2.Add(servicio.getIni)
  14.             lista3.Add(servicio.getfin)
  15.         End While
  16.         Comando.Connection.Close()



Espero te sirva.
Saludos.
__________________
La verdadera sabiduría está en reconocer la propia ignorancia.