根据多个条件查询。下面是我写的,但不对。看看不哪里错了。
 
string sql = string.Format("Select * From KeHuOfTable where Sex = '{0}'and Height between {1} and {2} and CV = '{3}' and Age between {4} and {5} and CarV = '{6}' and Kidney = '{7}' and Earning = {8} and Mv = '{9}'", cboSex.Text.Trim(),txtHeight.Text.Trim(),txtHeights.Text.Trim(),cboEducation.Text.Trim(),txtAge.Text.Trim(),txtAges.Text.Trim(),cboCar.Text.Trim(),cboKidney.Text.Trim(),txtIncome.Text.Trim(),cboMarriage.Text.Trim());
报错的说的是and附近有语法错误。。

解决方案 »

  1.   


    Select * From KeHuOfTable where Sex = '{0}' and Height between '{1}' and '{2}' and CV = '{3}' and Age between '{4}' and '{5}' and CarV = '{6}' and Kidney = '{7}' and Earning = '{8}' and Mv = '{9}'
      

  2.   

    Select * From KeHuOfTable where Sex = '{0}'and Height between {1} and {2}
    是不是这里的and和前面的没有空格?
      

  3.   

    可以加断点,调试一下,打印出SQL语句
      

  4.   

    Look the SQL carefully:
    Select * From KeHuOfTable 
    where Sex = '{0}'
    and Height between {1} and {2} 
    and CV = '{3}'
    and Age between {4} and {5} 
    and CarV = '{6}' 
    and Kidney = '{7}' 
    and Earning = {8}
    and Mv = '{9}'
    Please note the value of the parameter
      

  5.   

    实在不行,把BETWEEN换成IN试试
      

  6.   

    还应该注意括号 ,要不就是其中的值 为空或者 null,导致断裂!所以int可以加上单引号!
    改成如下
    string sql = string.Format("Select * From KeHuOfTable where Sex = '{0}' and (Height between '{1}' and '{2}') and CV = '{3}' and (Age between '{4}' and '{5}' ) and CarV = '{6}' and Kidney = '{7}' and Earning = '{8}' and Mv = '{9}'", cboSex.Text.Trim(),txtHeight.Text.Trim(),txtHeights.Text.Trim(),cboEducation.Text.Trim(),txtAge.Text.Trim(),txtAges.Text.Trim(),cboCar.Text.Trim(),cboKidney.Text.Trim(),txtIncome.Text.Trim(),cboMarriage.Text.Trim());
      

  7.   

    Earning = '{8}'勒里加上个引号吧,孩子