|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
problem with recordset object
Hello! I've got a problem with recordset object.
Error type ADODB.Recordset (0x800A0E78) operation is not allowed if object is closed. Error is in line 31 . I attach you the code in orden to have a look!!!! The problem happends when I use an INSERT statemen; if I use a SELECT statement nothing happends. Which could be the error and solution to the problem? Thanks!!!!!!!! |
|
#2
|
|||
|
|||
|
Why are you using a recordset to do an insert? Just make the connection execute it.
|
|
#3
|
|||
|
|||
|
Ok I've downloaded your file and paste the code into a tmp.asp page of mine. I took away the comments you had made and this is the final result.
NOTE: Like I said, I haven't change anything yet I've simply took away the comments. ----------------------------------------------------------------------------------- <HTML> <HEAD> </HEAD> <BODY bgcolor=FFD038> <H1 align="center"> ALTA DE ALUMNOS </H1> <% dim Obj_Conn dim Obj_Rs dim SQL Set Obj_Conn=Server.CreateObject("ADODB.Connection") Set Obj_Rs=Server.CreateObject ("ADODB.Recordset") SQL="INSERT persona(nombre) values('gonzalo')" Obj_Conn.Open("provider=SQLOLEDB.1;database=secretaria;uid=pepe; pwd=pepe") Obj_Rs.Open SQL,Obj_Conn %> <p>Se ha establecido la conexion con la BBDD</p> <a href="./baja_alumnos.asp">Ver alumnos</a> <% Obj_Rs.Close Obj_Conn.Close SET Obj_Rs=Nothing SET Obj_Conn=Nothing %> <p>Se ha cerrado la conexion con la BBDD</p> </BODY> </HTML> ----------------------------------------------------------------------------------- Now the first thing that I've notice is WHY are you intermingling your ASP code with the HTML code??? After all, your simply making an INSERT query that's it that's all so why mix it with your HTML??? Why not simply put it at the beginning(top) of your asp page this way you'll clarify your code. Another thing, I've notice that your INSERT statement is wrong, shouldn't it be INSERT INTO TableName ... Notice the *INTO* Now to make this clearer, let's try and keep the ASP code together and the same thing with the HTML. The end result should look something like: ----------------------------------------------------------------------------------- <%@ Language=VBScript %> <% dim Obj_Conn dim Obj_Rs dim SQL Set Obj_Conn=Server.CreateObject("ADODB.Connection") Set Obj_Rs=Server.CreateObject ("ADODB.Recordset") SQL="INSERT INTO persona(nombre) values('gonzalo')" Obj_Conn.Open("provider=SQLOLEDB.1;database=secretaria;uid=pepe; pwd=pepe") Obj_Rs.Open SQL,Obj_Conn Obj_Rs.Close Obj_Conn.Close SET Obj_Rs=Nothing SET Obj_Conn=Nothing %> <HTML> <HEAD> </HEAD> <BODY bgcolor=FFD038> <H1 align="center"> ALTA DE ALUMNOS </H1> <p>Se ha establecido la conexion con la BBDD</p> <a href="./baja_alumnos.asp">Ver alumnos</a> <p>Se ha cerrado la conexion con la BBDD</p> </BODY> </HTML> ----------------------------------------------------------------------------------- Notice the INTO keyword that I've added for you. Another thing...why are you creating a Recordset Object ??? Your query is an INSERT right? INSERT's don't return a recordset, it inserts data in your database that's it that's all so why create the overhead in your code ? So that's it for your code, but then you say...I want to use a SELECT query! Well if it is a SELECT Query then the process changes a bit in the sense that yes you'll need a Recordset Object. Hope this helps! Sincerely Vlince |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > problem with recordset object |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|