我的mysql查询是正确的,但在vb.net中是错误的

时间:2014-01-29 08:39:14

标签: sql vb.net

搜索文本框

这是我的查询正确查询

Select tip_part_no as TIPPartNo, date_rec as DateRecieve, reciever_name as RecieverName,
qty, SUM(qty) as Total from pcba_info.lot_info where tip_part_no like '' group by 
packing_list_no;
程序vb中的

错误,净T_T

("Select tip_part_no as TIP, SUM(qty) as Total_Quantity from pcba_info.lot_info 
WHERE tip_part_no LIKE '%" & Trim(txtsearch.Text.TrimEnd()) & "%' group by 
tip_part_no '%" , con)

2 个答案:

答案 0 :(得分:2)

您应该为此使用参数化查询...

您的查询如下所示:

Select tip_part_no as TIPPartNo, date_rec as DateRecieve, 
reciever_name as RecieverName, qty, SUM(qty) as Total from pcba_info.lot_info 
where tip_part_no like @tip_part_no group by packing_list_no;

然后添加值为@tip_part_no

的参数txtsearch.Text.Trim()

有关在参数化查询中使用LIKE运算符的信息:Parameterized Queries with LIKE and IN conditions

此处的示例和背景信息:How do I create a parameterized SQL query? Why Should I?

答案 1 :(得分:0)

删除分组依据(group by tip_part_no '%")附近的%,'(百分比和单引号)符号

试试这个

"Select tip_part_no as TIP, SUM(qty) as Total_Quantity from pcba_info.lot_info 
WHERE tip_part_no LIKE '%" & Trim(txtsearch.Text.TrimEnd()) & "%' group by 
tip_part_no" , con