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

thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.