Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Closed Recordset?
Message
General information
Forum:
Visual C++
Category:
Other
Miscellaneous
Thread ID:
00250082
Message ID:
00250101
Views:
24
Perfect! Now here is an example of when you need to use the Connection object! When you use the Recordset.Open method, ADO expects to get records back from the data source. Since you are doing an Insert, there aren't any records coming back and so you get the error (although the error message doesn't really help you to know that).

The way to do this is to use the Execute method of the Connection object. The code would look something like this:

' Create insert statement
new_qry = "Insert into cmts_unit_invty values('" & myvar1 & "'," & myvar2 & ")"

' Create Connection object
Set db_conn = Server.CreateObject("ADODB.Connection")

' Open connection using DSN
db_conn.Open "DSN=mydsn;UID=myid;PWD="

' Send the insert statement to the back end
db_conn.Execute new_qry

HTH

>I have 3 asp pages like:
>
>ASPpage1.asp:
>
>'<% dbf_qry = "select * from mytable"
>'Set db_rs = CreateObject("ADODB.Recordset")
>'db_rs.open dbf_qry, "DSN=mydsn;UID=myid;PWD="
>'%>
>
>'
>' Display contents of table
>'
>
>'<% db_rs.Close %>
>
>'A button is clicked and the page is redirected to ASPpage2.asp - a
>'page for data entry
>
>'ASPpage2.asp:
>
>'Contains a submit button and html textboxes, when submit button is
>'clicked results are passed on to ASPpage3 for processing
>
>'ASPpage3.asp:
>
>'<% myvar1 = Request.Form("textboxvar")
>'myvar2=99.99
>'new_qry = "Insert into cmts_unit_invty values(" & "'" & myvar1 & _
>' "'," & myvar2 & ")"
>'set new_rs = server.CreateObject("ADODB.Recordset")
>'new_rs.Open new_qry,"DSN=mydsn;UID=myid;PWD="
>'new_rs.Close
>'Response.Redirect("ASPpage1.asp")
>'%>
>
>I get the error message:
>
>The operation requested by the application is not allowed if the object is closed.
>
>Why is this and how can i solve this problem? Thanks for any solutions/suggestions.
>
>Carlos
>
>P.S. actual code is w/o comment delimiters
"It is an important and popular fact that things are not always what they seem. For instance, on the planet Earth, man had always assumed that he was more intelligent than dolphins because he had achieved so much -- the wheel, New York, wars and so on -- whilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than man -- for precisely the same reasons." - Douglas Adams
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform