c#多条件模糊查询语句的拼接 20
有6个文本框,对其中输入的内容进行拼接,但是不一定每个textbox都有内容输入,怎样用条件判断语句将所有可能都包括...
有6个文本框,对其中输入的内容进行拼接,但是不一定每个textbox都有内容输入,怎样用条件判断语句将所有可能都包括
展开
展开全部
用字符串拼接 StringBuilder
string sql = ""; //字符串拼接 按用户选择的条件来进行检索
StringBuilder sbuilder = new StringBuilder();
sbuilder.Append("select ID, Name, Sex, Age, Height, Nation, IdCard, HomeAddress, PhoneNumber, Birthday, Edu, Marriage, Professional, inputtime from EmployeeInfo where 1=1"); //sql 语句需要查询的东西,下面 进行拼接判断
if (!string.IsNullOrEmpty(employee.Edu)) { sbuilder.Append(" and Edu='" + employee.Edu + "'"); sql = sbuilder.ToString(); }
if (!string.IsNullOrEmpty(employee.Marriage)) { sbuilder.Append(" and Marriage='" + employee.Marriage + "'"); sql = sbuilder.ToString(); }
string sql = ""; //字符串拼接 按用户选择的条件来进行检索
StringBuilder sbuilder = new StringBuilder();
sbuilder.Append("select ID, Name, Sex, Age, Height, Nation, IdCard, HomeAddress, PhoneNumber, Birthday, Edu, Marriage, Professional, inputtime from EmployeeInfo where 1=1"); //sql 语句需要查询的东西,下面 进行拼接判断
if (!string.IsNullOrEmpty(employee.Edu)) { sbuilder.Append(" and Edu='" + employee.Edu + "'"); sql = sbuilder.ToString(); }
if (!string.IsNullOrEmpty(employee.Marriage)) { sbuilder.Append(" and Marriage='" + employee.Marriage + "'"); sql = sbuilder.ToString(); }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询