VB.NET-MYSQL - filter grid using combobox

1

hello good night everyone, again consulting to see if you can help me a pokito ... I have to filter a datagridview according to what I select in a combobox ... so far what I do is pass the id of the combobox item to a textbox, i that value (an integer) pass it as a parameter in the filter qery ... I have this function:

Public Sub filtrarNivel()
conexionMYSQL = New MySqlConnection

conexionMYSQL.ConnectionString = ("server=localhost;User Id=soporte;database=db_incidencias_muniquel;password=123")

Dim da As New MySqlDataAdapter

Dim dt As New DataTable

Dim fuente As New BindingSource

'Usamos un Capturador de Errores
Try
conexionMYSQL.Open()

'Dim query As String = "SELECT * FROM tbl_incidencias"

'Dim query As String = ("SELECT inc.id_incidencia, inc.fecha_registro, ingr.identificacion_metodo AS metodo, est.identificacion_estado AS estado, tip.identificacion_solicitud AS tipoSolicitud, niv.identificacion_nivel AS nivel, fun.nombre_funcionario as nombreSoporte, inc.detalle_incidencia FROM tbl_incidencias inc LEFT JOIN tbl_niveles_incidencia niv ON inc.id_nivel=niv.id_nivel LEFT JOIN tbl_tipo_solicitud tip ON inc.id_tipo_solicitud=tip.id_tipo_solicitud LEFT JOIN tbl_funcionario_soporte fun ON inc.id_registro_soporte=fun.id_registro_soporte LEFT JOIN tbl_estados_incidencia est ON inc.id_estado=est.id_estado LEFT JOIN tbl_metodos_ingreso_incidencia ingr ON inc.id_metodo_ingreso=ingr.id_metodo_ingreso WHERE inc.id_registro= @id_registro ")

Dim query As String = ("SELECT inc.id_incidencia, inc.fecha_registro, ingr.identificacion_metodo AS metodo, est.identificacion_estado AS estado, tip.identificacion_solicitud AS tipoSolicitud, niv.identificacion_nivel AS nivel, fun.nombre_funcionario as nombreSoporte, inc.detalle_incidencia FROM tbl_incidencias inc LEFT JOIN tbl_niveles_incidencia niv ON inc.id_nivel=niv.id_nivel LEFT JOIN tbl_tipo_solicitud tip ON inc.id_tipo_solicitud=tip.id_tipo_solicitud LEFT JOIN tbl_funcionario_soporte fun ON inc.id_registro_soporte=fun.id_registro_soporte LEFT JOIN tbl_estados_incidencia est ON inc.id_estado=est.id_estado LEFT JOIN tbl_metodos_ingreso_incidencia ingr ON inc.id_metodo_ingreso=ingr.id_metodo_ingreso WHERE inc.id_nivel=@id_nivel AND inc.id_registro='1'")

comando.Parameters.AddWithValue("@id_nivel", txtIdNivel.Text)

comando = New MySqlCommand(query, conexionMYSQL)

da.SelectCommand = comando

da.Fill(dt)

fuente.DataSource = dt

dgIncidenciasAsignadas.DataSource = fuente

da.Update(dt)

conexionMYSQL.Close()

Catch ex As Exception
MsgBox(ex.Message)
Finally
conexionMYSQL.Dispose()
End Try

but I get an error of coneversion select ... in integer and there I stay ... I appreciate it from now if someone has had a similar drama that could guide me

    
asked by Nicolas Ezequiel Almonacid 23.04.2018 в 03:21
source

1 answer

0

You have 2 errors in your code. On the one hand, the parameter of your query is happening as string , when by its name I imagine it is a int .

On the other hand, you are trying to access the Parameters collection of your command before defining the command.

With all this, these two lines of your code should be like this:

comando = New MySqlCommand(query, conexionMYSQL)
comando.Parameters.AddWithValue("@id_nivel", Convert.ToIn32(txtIdNivel.Text))
    
answered by 23.04.2018 / 17:09
source