| Más

Últimos miembros

DilanLonAndresNICOLASRolando RuizMARTIN PERALES SOCOLAJuan

FILTRAR LOS DATOS DE LA BASE DE DATOS EN VISUAL.NET

En esta aplicacion filtraremos los datos de una tabla desde visual estudio.

FORMULARIO
Private Sub cargar_combo(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Button2.Click
        Dim obj As New RN_productos
        Dim datos As New DataTable
        datos = obj.RN_leer_todos_prodcutos
        DataGridView1.DataSource = datos
 
        obj = Nothing
 
        Dim obj2 As New Rn_marcas
        Dim datos2 As New DataTable
        datos2 = obj2.RN_leer_todas_marcas
        With Cbo_marcas
            .DataSource = datos2
            .DisplayMember = "marca"
            .ValueMember = "id_marca"
        End With
    End Sub
………………………………………………………………….
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim obj As New RN_productos
        Dim datos As New DataTable
        datos = obj.RN_productos_xmarcas(Cbo_marcas.SelectedValue)
        DataGridView1.DataSource = datos
        obj = Nothing
 
 
    End Sub
 ..............................................
 

en la capa datos
Imports System.Data.SqlClient
Public Class BD_productos
    Public Function BD_leer_todos_productos() As DataTable
        Dim cn As New SqlConnection
        Try
            cn.ConnectionString = solo_conexion()
            Dim da As New SqlDataAdapter("sp_listar_productos", cn)
            Dim datos As New DataTable
            da.Fill(datos)
            da = Nothing
            Return datos
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Function BD_productos_xmarcas(ByVal xidmarcas As Integer)
        Dim cn As New SqlConnection
        Try
            cn.ConnectionString = solo_conexion()
            Dim da As New SqlDataAdapter("sp_productosxmarca", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@id_marca ", xidmarcas)
            Dim DT As New DataTable
            da.Fill(DT)
            Return DT
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Function BD_filtrar_productos(ByVal xproducto As String, ByVal xid_marca As Integer) As DataTable
        Dim cn As New SqlConnection
        Try
            cn.ConnectionString = solo_conexion()
            Dim da As New SqlDataAdapter("sp_filtrar_productos", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@prod", xproducto)
            da.SelectCommand.Parameters.AddWithValue("@id_marca", xid_marca)
            Dim datos As New DataTable
            da.Fill(datos)
            da = Nothing
            cn = Nothing
            Return datos
 
        Catch ex As Exception
            Return Nothing
 


        End Try

CLASE BD MARCAS
 
Imports System.Data.SqlClient
Public Class Bd_marcas
    Public Function BD_cbo_marcas() As DataTable
        Dim cn As New SqlConnection
        Try
            cn.ConnectionString = solo_conexion()
            Dim da As New SqlDataAdapter("sp_listar_marcas", cn)
            Dim DT As New DataTable
            da.Fill(DT)
            Return DT
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class
 

EN LA CAPA NEGOCIO
Imports Prj_capa_Datos
Public Class RN_productos
    Public Function RN_leer_todos_prodcutos() As DataTable
        Dim cn As New BD_productos
        Return cn.BD_leer_todos_productos
    End Function
    Public Function RN_productos_xmarcas(ByVal xmarck As Integer) As DataTable
        Dim cn As New BD_productos
        Return cn.BD_productos_xmarcas(xmarck)
    End Function
    Public Function RN_filtrar_productos(ByVal xprod As String, ByVal xidmarca As Integer) As DataTable
        Dim obj As New BD_productos
        Return obj.BD_leer_todos_productos
    End Function
End Class
-_______________________________________________________

CLASE RN MARCAS
 
Public Class Rn_marcas
    Public Function RN_leer_todas_marcas() As DataTable
        Dim chio As New Bd_marcas
        Return chio.BD_cbo_marcas
    End Function

End Class
__________________________
________________________________________________________________________



 



 


© 2020 Multiservicios Erwin