I m trying to filter a datagridview (connected to sql server). I have used if statements in order to take all the possible combination but now I have 8 textboxes into which the user should insert values and filter the datagridview.. it is too complex.. I have asked in the past but I didn t acheived to find a solution.. So HELP me plz!!
the problem i would like to write a sql query in order to filter a datagridview. The user insert in 8 text boxes the filter criteria but what if he want to insert only the two of them???? How the null textbox Texts could be ignored???
I ve tryed using if statements.. take a look of my query plz
query = "Select * from T_INCIDENTS1 where IFF (txtPostcode.text is notNull) then Incident_Postcode='" & txtPostcode.Text & "') and iff (txtDMA.text is notNull) then Incident_DMA='" & txtDMA.Text & "') "
dim Query as string
Query = "Select * from T_INCIDENTS1 where 1=1"
'now for example you have 2 textboxes , txt1,txt2 , for you filter
if txt1.text<>"" then
Query = Query & " And IFF (txtPostcode.text is notNull) then Incident_Postcode='" & txt1.Text & "')"
end if
if txt2.text<>"" then
Query = Query & " and iff (txtDMA.text is notNull) then Incident_DMA='" & txt2.Text & "') "
end if
dim Query as string
Query = "Select * from T_INCIDENTS1 where 1=1"
'now for example you have 2 textboxes , txt1,txt2 , for you filter
if txt1.text<>"" then
Query = Query & " And Incident_Postcode='" & txt1.Text & "')"
end if
if txt2.text<>"" then
Query = Query & " and Incident_DMA='" & txt2.Text & "') "
end if