那你先加个判断 if(this.textBox2.Text.Trim() != "") { sql = string.Format("select * from jobs where job_desc like '%{0}%'",this.textBox2.Text.Trim()); } else { sql = string.Format("select * from jobs" ); }可能因为 %空格%,或者 %%
select * from jobs where job_desc like '%{0}%' Select * From jobs where job_desc='{0}'两处不一致
select * from jobs where job_desc like '%{0}%这不是做了模糊查找了吗
把 string sql = string.Format("select * from jobs where job_desc like '%{0}%'",this.textBox2.Text.Trim()); 中的红色部分换成: ("select * from jobs where instr(job_desc,upper('%{0}'))>0 or instr(job_desc,lower('%{0}'))<0",this.textBox2.Trim()); 了解下like的作用就知道问题的原因所在了.
("select * from jobs where job_desc like '%'+this.textBox2.Text.Trim()+"'%'"); 模式运算符没效!改改吧!
上面漏写了个"%" ("select * from jobs where instr(job_desc,upper('%{0}%'))>0 or instr(job_desc,lower('%{0}%')) <0",this.textBox2.Trim());
string sql = string.Format("select * from jobs where job_desc like '%{0}%'",this.textBox2.Text.Trim()); 这就是模糊查询呀!
if(this.textBox2.Text.Trim() != "")
{
sql = string.Format("select * from jobs where job_desc like '%{0}%'",this.textBox2.Text.Trim());
}
else
{
sql = string.Format("select * from jobs" );
}可能因为 %空格%,或者 %%
Select * From jobs where job_desc='{0}'两处不一致
("select * from jobs where instr(job_desc,upper('%{0}'))>0 or instr(job_desc,lower('%{0}'))<0",this.textBox2.Trim());
了解下like的作用就知道问题的原因所在了.
模式运算符没效!改改吧!
("select * from jobs where instr(job_desc,upper('%{0}%'))>0 or instr(job_desc,lower('%{0}%')) <0",this.textBox2.Trim());
这就是模糊查询呀!