Hi all!

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???

Plz Plz help me!!! I have tryed it for days.. :S

Recommended Answers

All 6 Replies

please post also your codes here. in that way we can help you with your problem..

hello skran !
are you using sql query to get filtered records from database and show them in datagrid.???

Regards

yes

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 & "')  "

but there is an error near keyword 'is'

ok :) now you can do like this

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

Hope this will solve your prob .

Regards

right code is

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
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.