|
 |
access_asp thread: INSERT to table problem
Message #1 by "Leonid" <vleonid@m...> on Fri, 7 Feb 2003 18:02:29
|
|
Hi
I am missing something I don?t know.
If anybody can help me to solve this problem:
If I perform select statement then it is working
But when I am trying to insert then error?
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/test/customer_registration.asp, line 16
This is the script:
<%
Dim strSQL
strSQL = " insert into TestTable (lastname, firstname) values
('test_ln', 'test_fn')"
' This is comented working SELECT statement
'strSQL = " select lastname, firstname from TestTable "
Set fp_conn = Server.CreateObject("ADODB.Connection")
Set fp_rs = Server.CreateObject("ADODB.Recordset")
fp_conn.Open Application("db_ConnectionString")
fp_rs.Open "TestTable", fp_conn
Set fp_rs = fp_conn.Execute(strSQL)
Response.Write (strSQL)
fp_rs.Close
fp_conn.Close
%>
This is small ?TestTable? with 2 columns,
no relationships, no primary key.
Thanks.
Leonid
vleonid@m...
Message #2 by "Misconin, Michael" <Michael.Misconin@n...> on Fri, 7 Feb 2003 13:03:28 -0500
|
|
Leonid,
Sounds like you are trying to insert values before you do an
objconnection.open command.
I use the following when inserting values into a SQL table:
<%
'Request variables from Form
lastname = Replace(Request.Form("lastname"),"'","''")
firstname = Replace(Request.Form("firstname"),"'","''")
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Open CONNECTION_STRING
'Create SQL insert String from variables
strSQ = "'"
InsertSQL = "INSERT INTO TestTable (lastname, firstname) " & _
" values ('" & lastname & "', '" & firstname & "')"
Set RS = objConnection.Execute (InsertSQL)
%>
When selecting values back replace the InsertSQL string with:
SQL = "SELECT * from TestTable"
I usually put these sql commands in my confirmation page. Use the Form POST
method.
Hope this helps,
Mike
-----Original Message-----
From: Leonid [mailto:vleonid@m...]
Sent: Friday, February 07, 2003 1:02 PM
To: Access ASP
Subject: [access_asp] INSERT to table problem
Hi
I am missing something I don't know.
If anybody can help me to solve this problem:
If I perform select statement then it is working
But when I am trying to insert then error...
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/test/customer_registration.asp, line 16
This is the script:
<%
Dim strSQL
strSQL = " insert into TestTable (lastname, firstname) values
('test_ln', 'test_fn')"
' This is comented working SELECT statement
'strSQL = " select lastname, firstname from TestTable "
Set fp_conn = Server.CreateObject("ADODB.Connection")
Set fp_rs = Server.CreateObject("ADODB.Recordset")
fp_conn.Open Application("db_ConnectionString")
fp_rs.Open "TestTable", fp_conn
Set fp_rs = fp_conn.Execute(strSQL)
Response.Write (strSQL)
fp_rs.Close
fp_conn.Close
%>
This is small "TestTable" with 2 columns,
no relationships, no primary key.
Thanks.
Leonid
vleonid@m...
|
|
 |