根据多个条件查询。下面是我写的,但不对。看看不哪里错了。
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附近有语法错误。。
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附近有语法错误。。
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}'
是不是这里的and和前面的没有空格?
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
改成如下
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());