Quantcast
Channel: ¡AYUDA!, filtrar DataGridView. MySQL.
Viewing all articles
Browse latest Browse all 4

¡AYUDA!, filtrar DataGridView. MySQL.

$
0
0

Hola tengo un problema que me trae loco, llevo horas intentándolo resolver, pero estoy bloqueado, simplemente necesito buscar información en un DataGridView mediante filtros.

Este es el código que utilizo:

Variables.

Dim Filter As String
Dim Dataset As DataSet

LLAMO A LA FUNCIÓN DESDE EL LOAD DE LA FORMA.

buscarContactos()

Función para buscar contacto.

Public Sub buscarContactos() Dim Connection As New MySqlConnection Connection = New MySqlConnection(ConnectionString) Dim Adapter As New MySqlDataAdapter("SELECT * FROM tblcontactos", Connection) Dim DataSet As New DataSet Adapter.Fill(DataSet) dv.Table = DataSet.Tables(2)

dgvContactos.Columns(0).DataPropertyName = "conCodigo" dgvContactos.Columns(1).DataPropertyName = "conNombre" dgvContactos.Columns(2).DataPropertyName = "conApellido" dgvContactos.Columns(3).DataPropertyName = "conEmail" dgvContactos.Columns(4).DataPropertyName = "conTelefono" dgvContactos.DataSource = dv End Sub

Textbox, búsqueda rápida.

Private Sub txtBuscar_contacto_TextChanged(sender As Object, e As EventArgs) Handles txtBuscar_contacto.TextChanged 
        If cmbFiltro.SelectedIndex = 0 Then
            Filter = String.Empty
        End If
        If cmbFiltro.SelectedIndex = 1 Then
            Filter = "conCodigo"
        End If
        If cmbFiltro.SelectedIndex = 2 Then
            Filter = "conNombre"
        End If
        If cmbFiltro.SelectedIndex = 3 Then
            Filter = "conApellido"
        End If
        If cmbFiltro.SelectedIndex = 4 Then
            Filter = "conEmail"
        End If
        If cmbFiltro.SelectedIndex = 5 Then
            Filter = "conTelefono"
        End If

        dv.RowFilter = "[" & Filter & "]" & " LIKE '%" & txtBuscar_contacto.Text & "%'"
    End Sub

ERROR: Error al crear el formulario. Consulte Exception.InnerException para obtener más detalles. Error: La expresión contiene un nombre no válido: '[] LIKE '%Buscar en contactos.%''.

Al parecer no detecta el filter, si lo pongo sin corchetes ("[]" no se si de diga igual en otros países), me aparece lo siguiente,

dv.RowFilter = Filter & " LIKE '%" & txtBuscar_contacto.Text & "%'"

ERROR: Error al crear el formulario. Consulte Exception.InnerException para obtener más detalles. Error: Error de sintaxis: falta el operando antes del operador 'Like'.

Espero y puedan ayudarme, de antemano, gracias.



Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles


Te koop: Coebelweg 87, Leiden


Iomax kopen ionamin kopen 2019 orgineel iomax


Aantal jewels automatic horloge


Pelzner Saffraanvink


Aan weerszijden steken afkanten voor de armsgaten


Veiling tbv Het Marathonduivenjournaal (12)


Te koop: Zuidbuurtseweg 2, Zoeterwoude


Timewave DSP-599zx


Alexandra Daddario topless in True Detective


10-11-2015 Guillaume Wouter van Weele 68j te Bergen NH





Latest Images