Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why cant I delete more than one record at a time with this code?

Status
Not open for further replies.

MM777

IS-IT--Management
Mar 3, 2001
1
SE
Hi Everybody!


I try to delete more than one record in a single operation with this script,
but it only deletes one record at a time, could someone tell me what I'm
doing wrong here?


<%@LANGUAGE=&quot;VBSCRIPT&quot;%>

<!-- #include file=&quot;adovbs.inc&quot; -->
<%
Set Connect = Server.CreateObject(&quot;ADODB.Connection&quot;)
Connect.Open &quot;dsn=products;&quot;

Set RecSet = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Radera = &quot;SELECT * FROM tblProducts WHERE KatIDX LIKE '3'&quot;

RecSet.Open Radera, Connect, adOpenStatic, adLockOptimistic
%>
<%do until RecSet.EOF%>

<%for each x in RecSet.Fields%>
<%RecSet.Delete%>
<%next
RecSet.MoveNext%>

<%loop
RecSet.close
Connect.close
%>

Cheers

Magnus




 
I am not sure if this will work but give it a shot...



<%
Set Connect = Server.CreateObject(&quot;ADODB.Connection&quot;)
Connect.Open &quot;dsn=products;&quot;

Set RecSet = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Radera = &quot;SELECT * FROM tblProducts WHERE KatIDX LIKE '3'&quot;

RecSet.Open Radera, Connect, adOpenStatic, adLockOptimistic

do until RecSet.EOF
RecSet.Delete
RecSet.MoveNext
loop
RecSet.close
Connect.close
%>
Gordon R. Durgha
gd@vslink.net
 
if katIDX is a number, and you aren't using the % things, why not just make your sql statement say:

DELETE FROM tblProducts WHERE (KatIDX = 3)

then, instead of using a recordset, use the connection object to execute the sql.

ex:
dim c, sqlStr
sqlStr = &quot;DELETE FROM tblProducts WHERE (KatIDX = 3)&quot;
set c = server.createobject(&quot;adodb.connection&quot;)
c.open &quot;DSN=thisDSN&quot;
c.execute sqlStr
c.close

this is better for a couple reasons.
1) you don't need to create another object (the recordset object) making your page overhead smaller, and also making your page quicker.

2) by using the connection object, it's much quicker than using a recordset to delete from the DB.

if you need to use the like function, it should work within the sqlStr as well, but it will only work if the data type is a text data type.



good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top