c# - How to search with multiple criteria from a database with SQL? -


I am a newbie programmer. I have a page that looks like I have a car database and I have a database with this page There are several criteria to search for which users can enter value and can select. But the user does not have to fill or choose all the criteria. For example, a user can search for a car that depends only on "Mark" or it can be searched which depends on the year = "2007" fuel = "diesel" gear = "automated" ... etc ... My problem is how to design a query, find out which control values ​​are or not I use C # and MSSQL server.

You should make your query flexible enough (to control all paragraphs ) For all search conditions to work, consider the same example if the user has just entered the Mark field, and the remaining empty

sample code, suppose you have these parameters

@mark varchar (20) @series varchar (20) @model varchar (20) * Select from tbl where (the @ icon is empty or Mark C Lum = @ sign) and (@ series is zero or series column = @ series) and (@model is zero or model column = @model)

I want to sip all the parameters First of all, I repeat to pass. This avoids dynamic creation of queries and should avoid SQL injection.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -