Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Operation is not allowed in this context.


Message #1 by "André" <Andre_Ericsson@m...> on Sun, 14 Jul 2002 11:29:33
I know its all very messed up, but its not done, I will clean it up when 
it works 2 100%...
Error: 
ADODB.Recordset error '800a0c93' 

Operation is not allowed in this context. 



Code
--------------

<% Response.Buffer = True
Set Connect = Server.Createobject("ADODB.Connection")
Connect.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & 
server.mappath("/claninstant/db/poll.mdb")
set rs = Server.Createobject("ADODB.RecordSet")
Visa = "SELECT * From Fragor"
rs.Open Visa, Connect, 2, 3
'Kontroll
If NOT Request.Form("Fraga") <> "0" OR NOT Request.Form("Alt1") <> "0" OR 
NOT Request.Form("Alt") <> "0" Then
Response.Write("Du måste fylla i alla nödvändiga fält!")
Else

'Slut av Kontroll

Function Check(nr)
If Request.Form("Alt" & nr) <> "0" Then
rs("Alternativ_" & nr) = Request.Form("Alt" & nr)
Else
rs("Alternativ_" & nr) = ""
rs.Update
End If
End Function

For R = 1 to 10
Response.Write Check(R)
Next

Visa = "SELECT * From Poll"

' ****************
'Error on the line below
' ****************
rs.Close
' ****************
'Error on the line above
' ****************

rs.Open Visa

Function Check2(nr)
rs("Svar_" & nr) = ""
End Function

rs("Svar") = ""
rs("Question") = Request.Form("Fraga")
For T = 1 to 10
Response.Write Check2(T)
Next
If Request.Querystring("i") = "4" Then
rs.Close
Visa = "SELECT * from Poll"
rs.Open Visa

Dim incVote(10)
Dim incSvar

For I = 1 to 10
incVote(I) = rs("Svar_" & I) + 1
Next

rs("Svar_" & Request.Form("rosta")) = incVote(Request.Form("rosta"))
rs("Svar") = rs("Svar") + 1

rs.Update

Response.Cookies("Frys") = "Voted"
Response.Cookies("Frys").Expires = DateAdd("d",1,Date) 
End If
End If
Response.Redirect("poll.asp")
rs.Close
Connect.Close

%>
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 15 Jul 2002 14:12:15 +1000
In your function you have the following logic:

<%
Function DoStuff(argument)

    If Condition then
        RS(field) = Argument
    Else
        RS(field) = Argument
        RS.Update
    End If

End Function
%>

You call this function 10 times before you try to close the recordset.
Notice that you only call the .Update method inside one of the conditionals?

Second, using "magic numbers" is a really bad way to code - how do you know
(or how to we know) that you actually have an updatable recordset?

Thirdly, you are doing:

Response.Write(Check(R))

But the "Check" function doesn't return anything...Also, functions should be
used when you want to return something. If you are just doing a task, then
use a subroutine (Sub)

Lastly, since your function is just updating the same recordset field, and
you don't pass the recordset to the function, why don't you change your code
to make it a little more "encapsulated", by having it return the value that
you want:

<%
Function Check( _
    ByVal nr _
    )

    If Request.Form("Alt" & nr) <> "0" Then
        Check = Request.Form("Alt" & nr)
    Else
        Check = ""
    End If

End Function
'
'
For R = 1 to 10
    rs("Alternativ_" & nr) = Check(R)
Next
%>

Cheers
Ken


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "André" <Andre_Ericsson@m...>
Subject: [asp_databases] Operation is not allowed in this context.


: I know its all very messed up, but its not done, I will clean it up when
: it works 2 100%...
: Error:
: ADODB.Recordset error '800a0c93'
:
: Operation is not allowed in this context.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Return to Index