Hi all!

I try to filter a datagridview and I wrote an sql statement for that reason. The problem is that although I achieved to have multifilter I can find how to make my cod ignore the criteria which are null (empty criteria, when the user doesn t give any values). I tried the code below but I know that it isn t correct. "Select * from INCIDENTS where (DMA =Is NULL OR DMA='" & txtDMA.Text &'") AND (StreetName IS NULL or StreetName LIKE '" & txt.text & "%' )" Plz help!

You could build the query like

Dim query As String = "select * from Incidents"

If txtDMA.Text <> "" Or txtStreet.Text <> "" Then
    query &= " where "
    If txtDMA.Text <> "" Then
        query &= "DMA = '" & txtDMA.Text & "'"
    End If
    If txtStreet.Text <> "" Then
        If txtDMA.Text <> "" Then
            query &= " AND"
        End If
        query &= " StreetName LIKE '%" & txtStreet.Text & "%'"
    End If
End If
This question has already been answered. Start a new discussion instead.