日期:2014-05-18  浏览次数:20756 次

C# SQL2000 查询%%请教
C# SQL2000 查询%%请教 新手
  adapter = new SqlDataAdapter(@" SELECT G.CODE as 编码, G.NAME as 名称,G.SPEC as 规格,GU.PPRICE as 参考单价 FROM GOODSUNIT GU LEFT JOIN GOODS G ON GU.GOODSID=G.GOODSID where gu.goodsid in (select goodsid from goods where code= '"+Convert.ToString(textBox1.Text)+ " ' )", conn);如果

这里的(select goodsid from goods where code= '"+Convert.ToString(textBox1.Text)+ " ' )", 

如果改为where like '"+Convert.ToString(textBox1.Text)+ " ' )", 
改为条件like %内容%
应该怎么改呢?

------解决方案--------------------
select goodsid from goods where code like '%"+Convert.ToString(textBox1.Text)+ "%'
------解决方案--------------------
1.textBox1.Text本来就是string不必转换了
2.where like '%"+textBox1.Text+ "%'", 

------解决方案--------------------
1.textBox1.Text本来就是string不必转换了
2.where code like '%"+textBox1.Text+ "%'",

------解决方案--------------------
select goodsid from goods where code= '%"+Trim(textBox1.Text)+ "% '

加上trim,去掉首尾空格