我想要在当前日期的过去一周内找到tblCreatedItems和tblInventory的总数。tblCreatedItems的合计显示得非常好。但是针对tblInventory的版本根本没有显示出来。
我的表是: tblItem(ItemID,ItemName,Quantity) tblCreatedItems(ItemID,Quantity) tblInventory(IngredientName,Price,Quantity)
目前这是我的代码:
<% dim Con,rs, sql
set con = server.CreateObject("ADODB.Connection")
set rs = server.CreateObject("ADODB.Recordset")
Con.Open("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" & Server.MapPath("Database/Name.accdb"))
sql = "SELECT tblItem.Price, tblCreatedItems.Quantity, tblCustomer.OrderDate, Price InventoryPrice FROM tblCreatedItems,tblInventory, tblItem, tblCustomer WHERE tblCustomer.OrderDate BETWEEN Date() AND Date()-6 AND tblItem.ItemID=tblCreatedItems.ItemID AND tblCustomer.CustomerID=tblCreatedItems.CustomerID"
rs.open sql, Con
%>
<form name="InsertFinancialInformation" method="post" action="">
<table class="Table" align="center" >
<th colspan="4">Financial Information Entry</th>
<tr><td colspan="4" bgcolor="#999999">Cost of Sales:</td></tr>
<tr>
<td>Opening Stock</td>
<td>Purchases</td>
<td>Gross Profit</td>
</tr>
<tr>
<%while not rs.eof%>
<%
dim Total
Total = Total + (rs("Price")*rs("Quantity"))
%>
<% rs.movenext
wend
%>
<td><input type="text" name="" value="<%response.write(Total)%>"/></td>
<td><input type="text" name="" value="
<%while not rs.eof%>
<%
dim InventoryTotal
InventoryTotal = InventoryTotal + (rs("tblInventory.Price")*rs("tblInventory.Quantity"))
%>
<% rs.movenext
wend
%>
<%response.write(InventoryTotal)%>"/></td>
<td><%response.write(Total-InventoryTotal)%></td>
</form>发布于 2015-12-23 00:00:32
您的第一个循环是遍历记录集,直到它到达末尾。然后,您的第二个循环尝试执行相同的操作。但是,记录集已经在末尾,因此没有任何记录需要循环遍历。你需要在第二次循环之前重新查询数据库,或者使用rs.movefirst (我不太确定这是不是经典的asp的有效命令)。
https://stackoverflow.com/questions/34365848
复制相似问题