最近又做了一个项目,其中有一个功能是利用G
ridView做个采购列表,一个是手动添加型的,另一个是根据订单与产品信息自动生成的,两种表中都有checkbox用来选择要采购哪个产品,然后点击生成采购单按钮生成选择的要生产的物件的采购单,其中手动那个没有问题,自动生成那个因为GridView中引用了两个表的数据,在采购单生成功能按钮那里的代码一直出错,查了许多资料也尝试了很多写法但都不行,贴上出错的代码希望大家给点指点或思路
手动填写采购单页面相关功能的代码(未出错)
public DataTable BuyManagerSelectByID(string id)
{
string sql="select*from dbo.buymanager where ID in ("+id+") order by ID desc";
try
{
return data.RunProcReturn(sql);
}
catch(Exception ee)
{
data.MessageBox(ee.Message.ToString());
return null;
}
}
自动生成采购单列表的相关代码(出错)
public DataTable GVAUTO(string Pnum)
{
string sql="select*from dbo.productInfo and dbo.orderInfo where Pnum in ("+Pnum+") order by Pnum desc";//出错 关键字“and”附近有语法错误;and去了依然报错,列名Pnum不明确
下面的就跟上面的一样了
……
}
希望各位能看一下,给个解决问题的办法或思路
SELECT *
FROM orderInfo
LEFT JOIN productInfo
ON orderInfo.pnum=productInfo.pnum
ORDER BY orderInfo.pnum desc //我是不明白你order by pnum有什么意义。一般都是order by xx.name或者xx.date
功能可以实现了,我是这样写的
string sql="select*from orferInfo left join productInfo on orderInfo.Pnum=productInfo.Pnum where productInfo.Pnum in ("+Pnum+") order by orderInfo.Pnum desc";
非常感谢前辈的指点,接下来我会尽量抽时间学习SQL并巩固C#的,因为接下来我就要搞建模了#皿#