现在的位置: 首页 > 综合 > 正文

VS2005中TableAdapter中实现动态查询并使用LIKE的方法整理

2013年12月10日 ⁄ 综合 ⁄ 共 1161字 ⁄ 字号 评论关闭

VS2005中TableAdapter中实现动态查询并使用LIKE的方法整理

TableAdapter FILLBY 参数去空格问题

 

发现带入参数有问题 有空格

 

(解决思路是将 LIKE 放到语句里面)

 

 

 if (textBox1.Text.Length == 0 || textBox1.Text.ToString().Trim()=="" )
            {
                this.kgtLink2008DataSet.bak_product1.Clear();
                
                this.bak_product1TableAdapter.Fill(this.kgtLink2008DataSet.bak_product1);
                this.dataGridView1.DataSource = bakproduct1BindingSource;
            }
            else
            {
                this.kgtLink2008DataSet.bak_product1.Clear();
             
                StringBuilder p =new StringBuilder();
                p.Append("%");
                p.Append ( textBox1.Text.ToString().Trim());
                p.Append ("%");               
                this.bak_product1TableAdapter.FillBy(this.kgtLink2008DataSet.bak_product1, p.ToString());
                this.dataGridView1.DataSource = bakproduct1BindingSource;
            }

 这里

StringBuilder p =new StringBuilder();

p.Append("%");

p.Append ( textBox1.Text.ToString().Trim());

 p.Append ("%");

 

在tableAdapter中配置语句

 

SELECT ProdCode, BarCode, ProdName, DepCode, ClsCode, SupCode, SeatCode,

      BrandCode, Spec, Unit, ProdAdr, ProdType, ScaleType, Price, OPrice, OutOPrice,

      VipPrice1, VipPrice2, VipPrice3, WPrice, PSPrice, KCCount, Cost, OutCost, Total, OTax,

      STax, ProdMemo1, ProdMemo2, ShopDepCode, EditDate, EditUser, PControl,

      AidCode, TakeRate, GatherRate, NewDate, NewUser, MadeCode, BDscCode

FROM bak_product1

WHERE (BarCode LIKE @p) 

 

参数 p

 

抱歉!评论已关闭.