请教各位c#多条件查询,请教各位c#多条件查询请教各位c#多条件查询
多条件无非就是拼接下sql,用and连接各个条件。
Sql的话where 后面拼接条件 ef的话ToList().Where("")where里面写条件
sql的话用and拼接查询条件,用,分割
string sql = "select * from 表名 where 1=1 ";
if (textBox1.Text != "")
{
sql += " and 列1= '" + textBox1.Text + "'";
}
if (textBox2.Text != "")
{
sql += " and 列2 = '" + textBox2.Text + "'";
}
//以此类推
and前面记得加空格!