Reputation: 31
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?
Upvotes: 0
Views: 207
Reputation: 7676
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.
Upvotes: 2
Reputation: 420
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'*'....
Upvotes: 0