|
 |
asp_databases thread: How to:delete parameters from parameters collection
Message #1 by "Hassan Ali" <technofriend@i...> on Fri, 26 Jul 2002 06:20:23
|
|
Hello all,
i am a newly registered user on this forum, and i have a query which i
hope to get a solution for.
when i delete parameters from the parameters collection i am getting an
error . these are the details.
Dim oConn,oCmd,oRs,oParam
Set oCmd=Server.CreateObject("Adodb.Command")
Set oConn=Server.CreateObject("Adodb.Connection")
Set oParam=oCmd.Parameters
oConn.Open Session("oConn")
oCmd.ActiveConnection=oConn
oCmd.CommandText="sp_createMeeting"
oCmd.CommandType=adCmdStoredProc
With oParam
.Append oCmd.CreateParameter("@organiser",adInteger,adParamInput,,Session
("intUniqueId"))
.Append oCmd.CreateParameter("@subject",adVarChar,adParamInput,20,subject)
.Append oCmd.CreateParameter("@description",adVarChar,adParamInput,20,desc)
.Append oCmd.CreateParameter
("@location",adVarChar,adParamInput,20,location)
.Append oCmd.CreateParameter
("@duration",adVarChar,adParamInput,20,duration)
oCmd.Execute
End With
and using a for loop i am trying to delete
for i=0 to ocmd.parameters.count-1
ocmd.parameters.delete(i)
next
and also tried with
for i=0 to ocmd.parameters.count-1
oParam.delete(i).name
next
the loop delete only first three params and gives the error mentioned below
: ADODB.Command (0x800A0CC1)
::Item cannot be found in the collection corresponding to the requested
name : or ordinal.
i am able to solve this by using command object's refresh method but i do
not want to use that as it take a round to the provider to get the details
of parameters which again effects the performance ...
please guide me on this.
thank you very much in advance
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 29 Jul 2002 12:55:33 +1000
|
|
I think the logic is wrong -
Suppose you have 5 parameters. You are doing a loop from 0 to 4 - when you
delete parameter 0, you only have 4 parameters left (0 to 4). You then
delete parameter 1, which leaves you with 0-3 left. You then delete
parameter 2, which leaves 0-2, you then try to delete parameter 3 - and an
error is thrown.
Do:
<%
For i = objCommand.Parameters.Count - 1 to 0
...
Next
%>
(ie delete from the last to the first)
OR
<%
' Just delete the *first* parameter n-1 times
For i = 0 to objCommand.Parameters.Count - 1
objCommand.Parameters(0).Delete
Next
%>
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Hassan Ali" <technofriend@i...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, July 26, 2002 6:20 AM
Subject: [asp_databases] How to:delete parameters from parameters collection
: Hello all,
:
: i am a newly registered user on this forum, and i have a query which i
: hope to get a solution for.
:
: when i delete parameters from the parameters collection i am getting an
: error . these are the details.
:
: Dim oConn,oCmd,oRs,oParam
: Set oCmd=Server.CreateObject("Adodb.Command")
: Set oConn=Server.CreateObject("Adodb.Connection")
: Set oParam=oCmd.Parameters
:
: oConn.Open Session("oConn")
: oCmd.ActiveConnection=oConn
: oCmd.CommandText="sp_createMeeting"
: oCmd.CommandType=adCmdStoredProc
:
: With oParam
: .Append oCmd.CreateParameter("@organiser",adInteger,adParamInput,,Session
: ("intUniqueId"))
: .Append oCmd.CreateParameter("@subject",adVarChar,adParamInput,20,subject)
: .Append
oCmd.CreateParameter("@description",adVarChar,adParamInput,20,desc)
: .Append oCmd.CreateParameter
: ("@location",adVarChar,adParamInput,20,location)
: .Append oCmd.CreateParameter
: ("@duration",adVarChar,adParamInput,20,duration)
: oCmd.Execute
: End With
:
: and using a for loop i am trying to delete
:
: for i=0 to ocmd.parameters.count-1
: ocmd.parameters.delete(i)
: next
:
: and also tried with
:
: for i=0 to ocmd.parameters.count-1
: oParam.delete(i).name
: next
:
:
: the loop delete only first three params and gives the error mentioned
below
:
: : ADODB.Command (0x800A0CC1)
: ::Item cannot be found in the collection corresponding to the requested
: name : or ordinal.
:
:
: i am able to solve this by using command object's refresh method but i do
: not want to use that as it take a round to the provider to get the details
: of parameters which again effects the performance ...
:
: please guide me on this.
: thank you very much in advance
|
|
 |