EjemplosDuoc.es.tl
  Manejo de BD
 



'Permite realizar las 4 operaciones sobre la base de datos
Imports System.Data
Public Class manejodatopers
    Public cnn As New SqlClient.SqlConnection _
        ("Data Source=.SQLEXPRESS;AttachDbFilename=F:Documents and SettingsAdministradorEscritoriotrabajo3rowebApp_Dataempresa.mdf;Integrated Security=True;User Instance=True")
    Public comm As New SqlClient.SqlCommand("", cnn)
    Public datos(4) As String

    Function verificarper(ByVal rrr)
        '
        'VERIFICA LA EXISTENCIA DE UN CLIENTE
        '
        Dim res As Boolean = False
        cnn.Open()
        comm.CommandType = CommandType.Text
        comm.CommandText = "select * from Cliente where rut='" _
        & rrr & "'"
        Try
            Dim lee As SqlClient.SqlDataReader
            lee = comm.ExecuteReader
            lee.Read()
            If rrr = lee.GetString(0).Trim Then
                res = True
            End If
        Catch
            MsgBox("Cliente no ingresado", MsgBoxStyle.Critical, "BUSQUEDA DE CLIENTES")
        End Try
        cnn.Close()
        Return (res)
    End Function

    Function grabarper(ByVal rrr, ByVal nom, ByVal ape, ByVal dir, ByVal fec)
        '
        ' ALMACENA EN LA BASE DE DATOS LOS DATOS DE UN NUEVO CLIENTE
        '
        Dim res As String = 0
        cnn.Open()
        comm.CommandType = CommandType.Text
        comm.CommandText = "insert into Cliente values('" _
                            & rrr & "','" & nom & "','" _
                            & ape & "','" & dir & "','" _
                            & fec & "')"
        res = comm.ExecuteNonQuery()
        cnn.Close()
        Return (res)
    End Function


    Function modificarper(ByVal rrr, ByVal nom, ByVal ape, ByVal dir, ByVal fec)
        '
        ' GUARDA LOS CAMBIOS REALIZADOS POR EL USUARIO A LOS DATOS ENCONTRADOS EN LA BD
        '
        Dim res As String = 0
        cnn.Open()
        comm.CommandType = CommandType.Text
        comm.CommandText = "update Cliente set nombre='" _
                            & nom & "', apellidos='" & ape & "', direccion='" _
                            & dir & "', fecnac='" & fec & "' where rut='" & rrr & "'"
        res = comm.ExecuteNonQuery()
        cnn.Close()
        Return (res)
    End Function


    Sub listarpercom()
        '
        ' REALIZA EL LISTADO DE TODOS LOS CLIENTES EXISTENTES
        ' este metodo funciona solamente en aplicacion de escritorio
        cnn.Open()
        comm.CommandType = CommandType.Text
        comm.CommandText = "select * from Cliente"
        Try
            Dim lee As SqlClient.SqlDataReader
            lee = comm.ExecuteReader
            While lee.Read
                Form4.ComboBox1.Items.Add(lee.GetString(0))
            End While
        Catch
        End Try
        cnn.Close()
    End Sub

    Function buscarper(ByVal rrr)
        '
        ' REALIZA LA BUSQUEDA DE UN CLIENTE Y RETORNA SUS VALORES EN UN ARREGLO
        '
        cnn.Open()
        comm.CommandType = CommandType.Text
        comm.CommandText = "select * from Cliente where rut='" _
        & rrr & "'"
        Try
            Dim lee As SqlClient.SqlDataReader
            lee = comm.ExecuteReader
            lee.Read()
            datos(0) = lee.GetString(0)
            datos(1) = lee.GetString(1)
            datos(2) = lee.GetString(2)
            datos(3) = lee.GetString(3)
            datos(4) = lee.GetString(4)
        Catch

        End Try
        cnn.Close()
        Return (datos)
    End Function
End Class


 
   
 
Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis