Forums
This topic is locked
Deleting from Array results???
Posted 02 Dec 2005 20:24:01
1
has voted
02 Dec 2005 20:24:01 Greg LeBreck posted:
In asp using a SQL DB:Here is what I have:
' Get Question ID
Dim rsQidIs
Dim rsQidIs_numRows
Set rsQidIs = Server.CreateObject("ADODB.Recordset"
rsQidIs.ActiveConnection = MM_connSQL_STRING
rsQidIs.Source = "SELECT ID FROM dbo.FAQ_Questions WHERE CID = " & cdid
rsQidIs.CursorType = 0
rsQidIs.CursorLocation = 2
rsQidIs.LockType = 1
rsQidIs.Open()
rsQidIs_numRows = 0
quesid = rsQidIs("ID"
'Delete Question
set DCATQ = Server.CreateObject("ADODB.Command"
DCATQ.ActiveConnection = MM_connSQL_STRING
DCATQ.CommandText = "DELETE FROM dbo.FAQ_Questions WHERE CID = " & cdid
DCATQ.CommandType = 1
DCATQ.CommandTimeout = 0
DCATQ.Prepared = true
DCATQ.Execute()
Here is what I want to do:
The select statement may or may not bring back multiple id's. I then want the delete statement to delete everything with the one or multiple id's returned.
How can I do this?
Replies
Replied 02 Dec 2005 20:33:05
02 Dec 2005 20:33:05 Neal T replied:
I am in no ways qualified to set any code down, but some of things I have read have usually indicated,
1. Query the DB for the records...make sure that the query is working;
2. Perform a record count on the DB for those that you want to append...
3. Based upon that data recieved from the record count, utilize that in your arrays as a basis to loop through your record sets.
Just wait for someone else's response before you embark on this in case this is not a proper way to do it...but like I said, this seems like a way to do it from what I've read elsewhere.
1. Query the DB for the records...make sure that the query is working;
2. Perform a record count on the DB for those that you want to append...
3. Based upon that data recieved from the record count, utilize that in your arrays as a basis to loop through your record sets.
Just wait for someone else's response before you embark on this in case this is not a proper way to do it...but like I said, this seems like a way to do it from what I've read elsewhere.
Replied 13 Dec 2005 01:00:56
13 Dec 2005 01:00:56 Lee Diggins replied:
Hi Greg
Neals suggestion are good one's, have you sorted this or do still need help?
Something like below:
' Get Question ID
Dim rsQidIs
Dim rsQidIs_numRows
Set rsQidIs = Server.CreateObject("ADODB.Recordset"
rsQidIs.ActiveConnection = MM_connSQL_STRING
rsQidIs.Source = "SELECT ID FROM dbo.FAQ_Questions WHERE CID = " & cdid
rsQidIs.CursorType = 0
rsQidIs.CursorLocation = 2
rsQidIs.LockType = 1
rsQidIs.Open()
rsQidIs_numRows = 0
Do Until rsQidIs.EOF
quesid = quesid & rsQidIs("ID" & ","
rsQidIs.MoveNext()
Loop
cdid = Left(quesid, Len(quesid )-1)
'Delete Question
set DCATQ = Server.CreateObject("ADODB.Command"
DCATQ.ActiveConnection = MM_connSQL_STRING
DCATQ.CommandText = "DELETE FROM dbo.FAQ_Questions WHERE CID IN (" & cdid & ""
DCATQ.CommandType = 1
DCATQ.CommandTimeout = 0
DCATQ.Prepared = true
DCATQ.Execute()
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Neals suggestion are good one's, have you sorted this or do still need help?
Something like below:
' Get Question ID
Dim rsQidIs
Dim rsQidIs_numRows
Set rsQidIs = Server.CreateObject("ADODB.Recordset"
rsQidIs.ActiveConnection = MM_connSQL_STRING
rsQidIs.Source = "SELECT ID FROM dbo.FAQ_Questions WHERE CID = " & cdid
rsQidIs.CursorType = 0
rsQidIs.CursorLocation = 2
rsQidIs.LockType = 1
rsQidIs.Open()
rsQidIs_numRows = 0
Do Until rsQidIs.EOF
quesid = quesid & rsQidIs("ID" & ","
rsQidIs.MoveNext()
Loop
cdid = Left(quesid, Len(quesid )-1)
'Delete Question
set DCATQ = Server.CreateObject("ADODB.Command"
DCATQ.ActiveConnection = MM_connSQL_STRING
DCATQ.CommandText = "DELETE FROM dbo.FAQ_Questions WHERE CID IN (" & cdid & ""
DCATQ.CommandType = 1
DCATQ.CommandTimeout = 0
DCATQ.Prepared = true
DCATQ.Execute()
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>