简体   繁体   中英

Use * as a wildcard when searching a SQL query with Greater than or Less than

I am looking to perform a greater than or less than search on multiple columns from an access database in C#.

So far I am trying to compare a chassis number value that is stored in a access database against a value in a textbox. If that value is greater than the textbox, this would then return the relevant data stored in the database to a gridview.

so far my code is:

 var sql = "SELECT * FROM [database] WHERE (Manufacturer ='" + comboBox3.Text +
     "' OR Manufacturer='*') AND (Model ='" + comboBox4.Text + "' OR Model='*') AND (Fuel ='" +
     textBox9.Text + "' OR Fuel='*') AND (Chassisno='*' OR (Chassisno > '" + textBox2.Text + "'))";

The code above is finding results, but the 'greater than' operator is being ignored.

Does anybody have any ideas why this would be?

This portion:

Chassisno='*'

Causes the query to find anything. Please remove that part of the query if you are truly only interested in finding values that are greater than Chassisno.

you can't use * wild card with "=" , you should use "like" keyword :

.....OR Manufacturer like '*') AND (Model ='" + comboBox4.Text + "' OR Model like '*') AND (Fuel ='" +
 textBox9.Text + "' OR Fuel like '*') AND (Chassisno like'*'.... 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM