私は結婚大学のプロジェクトで高度な検索を行いました。その結果、次のクエリがありました。
select *
from tbl_FreeUserProfile
where Gender='Male' and Age>= '18'
and Age<= '40' and heightf<='182'
and heightf>='152' and MaritalStatus='Never Married'
and MotherTongue = 'xyz' or 'Gujarati' or 'Urdu' or 'Hindi'"
しかし、クエリを実行すると、次のエラーが表示されます。
'または'の近くの条件が予想されるコンテキストで指定された非ブール型の式
誰かがSQLクエリの形式の何が問題になっているのか教えてもらえますか?
私のコーディングはこんな感じです
protected void ImageButton11_Click(object sender, ImageClickEventArgs e)
{
string sql = "select * from tbl_FreeUserProfile where Gender='" + RadioButtonList2.SelectedItem.Text + "' and Age>= '" + DropDownList25.SelectedItem.Text + "' and Age<= '" + DropDownList26.SelectedItem.Text + "' and heightf<='" + TextBox23.Text + "' and heightf>='" + TextBox22.Text + "' and MaritalStatus='" + DropDownList35.SelectedItem.Text + "'";
if (ListBox2.Items.Count >= 0)
{
sql = sql + " and MotherTongue = 'xyz'";
for (int i = ListBox2.Items.Count - 1; i >= 0; i--)
{
string mt = ListBox2.Items[i].ToString();
sql = sql + " or '" + mt + "'";
}
}