Forums
This topic is locked
update query updating all records :S
Posted 24 Aug 2006 15:22:59
1
has voted
24 Aug 2006 15:22:59 mike lister posted:
<font face='Verdana'>using dw8 to make this page that when loaded it looks at the querystring id finds that record in table inktest > inkcartid > record and then updates the stock level field by simply subtracting 1 for the current number. i thought i had it figured when i created a recored set tellin it to use MMColParam 1 to find the record but it still updates all of them. any ideas what it is??<pre id=code><font face=courier size=2 id=code><%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/conndatabase.asp" -->
<%
Dim rsInkcart__MMColParam
rsInkcart__MMColParam = "1"
If (Request.QueryString("id" <> "" Then
rsInkcart__MMColParam = Request.QueryString("id"
End If
%>
<%
Dim rsInkcart
Dim rsInkcart_numRows
Set rsInkcart = Server.CreateObject("ADODB.Recordset"
rsInkcart.ActiveConnection = MM_conndatabase_STRING
rsInkcart.Source = "SELECT inkcartID, StockLevel FROM inktest WHERE inkcartID = " + Replace(rsInkcart__MMColParam, "'", "''" + ""
rsInkcart.CursorType = 0
rsInkcart.CursorLocation = 2
rsInkcart.LockType = 1
rsInkcart.Open()
rsInkcart_numRows = 0
%>
<%
Dim sql
set conn = server.CreateObject("adodb.connection"
conn.connectionstring = MM_conndatabase_STRING
conn.open
sql="UPDATE inktest SET "
sql=sql & "StockLevel=" & (rsInkcart.Fields.Item("StockLevel".Value) -1 & ""
on error resume next
conn.Execute sql
if err<>0 then
response.write("No update permissions!"
else
response.write("Record " & cid & " was updated!"
end if
conn.close
%>
<%
rsInkcart.Close()
Set rsInkcart = Nothing
%>
<a href="test.asp">link back
</a>
</font id=code></pre id=code></font id='Verdana'>
Replies
Replied 25 Aug 2006 18:45:23
25 Aug 2006 18:45:23 Mitchel Tendler replied:
On these lines:
sql="UPDATE inktest SET "sql=sql & "StockLevel=" & (rsInkcart.Fields.Item("StockLevel".Value) -1 & ""
I don't see anything that tell the update command to only update ONE PARTICULAR record. Seems like you are missing a WHERE clause.
sql="UPDATE inktest SET "sql=sql & "StockLevel=" & (rsInkcart.Fields.Item("StockLevel".Value) -1 & ""
I don't see anything that tell the update command to only update ONE PARTICULAR record. Seems like you are missing a WHERE clause.