日期:2014-05-16  浏览次数:20734 次

一句sql问题,求助如何调用啊!!!
sqltext2 = "select A.Product_Id,A.OrderNum,A.ProductUnit,A.BuyPrice,C.Title,C.Price,C.BigClassName,C.SmallClassName,C.DefaultPicUrl,C.spec,C.id from OrderDetail A,Product C where A.OrderNum='"&OrderNum&"' and A.Product_Id=C.Product_Id"

有两个表,一个是OrderDetail和Product。。然后我现在要调OrderDetail表里面的id出来,但是我用<%=rs("id")%>显示的总是Product表里面的ID!!!
我想调OrderDetail的ID得如何写????

------解决方案--------------------
你可以使用a.id as orderid

然后再调用的时候, 直接写上rs("orderid")就可以了.
------解决方案--------------------
在sql中把a表的id抽出来,在画面中显示。
sql文改为:sqltext2 = "select A.id as detailId, A.Product_Id,A.OrderNum,A.ProductUnit,A.BuyPrice,C.Title,C.Price,C.BigClassName,C.SmallClassName,C.DefaultPicUrl,C.spec,C.id from OrderDetail A,Product C where A.OrderNum='"&OrderNum&"' and A.Product_Id=C.Product_Id"

画面用<%=rs("detailId")%>显示。
------解决方案--------------------
rom OrderDetail A,Product C  数据库首先解析到了product,认为id是该表的id。
用了as 就是指定了别名,就不会混淆。