您的位置:首页 > 其它

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

2011-07-18 15:45 821 查看
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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: