Forums

ASP

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 &gt; inkcartid &gt; 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>&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;!--#include file="Connections/conndatabase.asp" --&gt;
&lt;%
Dim rsInkcart__MMColParam
rsInkcart__MMColParam = "1"
If (Request.QueryString("id" &lt;&gt; "" Then
rsInkcart__MMColParam = Request.QueryString("id"
End If
%&gt;
&lt;%
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
%&gt;
&lt;%
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&lt;&gt;0 then
response.write("No update permissions!"
else
response.write("Record " & cid & " was updated!"
end if

conn.close

%&gt;

&lt;%
rsInkcart.Close()
Set rsInkcart = Nothing
%&gt;
&lt;a href="test.asp"&gt;link back
&lt;/a&gt;
</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.

Reply to this topic