Ⅰ C#模糊查詢代碼怎麼寫
var sql = string.Empty;
if (string.IsNullOrEmpty(ComboBox1) && string.IsNullOrEmpty(ComboBox2))
{
sql = "select * from table";
}
else
{
if (!string.IsNullOrEmpty(ComboBox1) && !string.IsNullOrEmpty(ComboBox2))
{
sql = $"select * from table where xx like '%{ComboBox1}%' or xx like '%{ComboBox2}%'";
}
else
{
var like = string.IsNullOrEmpty(ComboBox1) ? ComboBox2 : ComboBox1;
sql = $"select * from table where xx like '%{like}%'";
}
}
//同是小白專屬