|
 |
asp_databases thread: Can't AddNew
Message #1 by "Phil Perks" <philp@w...> on Tue, 9 May 2000 14:39:31
|
|
-----Original Message-----
From: Keith Caselman [mailto:keith@c...]
Sent: 09 May 2000 05:24
To: support@w...
Subject: Can't AddNew
I am trying to add to a SQL Database, I have read the data from it may
times
in may different ways, but I can't seem to add a record to it. I am
getting
the Request.Forms to Response.Write but when I try to add to the database
I
get the error "ADODB.Recordset error '800a0cb3'
The operation requested by the application is not supported by the
provider.
/Insert/Specs/handler_for_insert_asp.asp, line 39 "
Below is the HTML and VBScript. I have granted the User "WEB" all rights
to
the database and tabel and the username and password works fine on other
pages. If you have any ideas, thanks ahead of time.
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Handler for Insert</title>
</head>
<body>
<p>Handler for Insert_Specs.asp</p>
<%
dim name
dim Notes
dim Model
VarName = Request.Form("FName")
VarNotes = Request.Form("FNotes")
VarModel = Request.Form("FModel")
Response.write (VarName)
Response.write "<p>"
Response.write (VarNotes)
Response.write "<p>"
Response.write (VarModel)
Response.write "<P>If you See three entries above, you know the varibles
are being passed."
Response.write "<HR>"
dim SpecsRS
set SpecsRS=Server.CreateObject("ADODB.recordset")
sqltext = "SELECT * FROM Specs;"
SpecsRS.open sqltext, "dsn=Cramalot; uid=web; pwd=2673560;3,3"
SPecsRS.AddNew
SpecsRS("Name") = VarName
SpecsRS("Notes") = VarName
SpecsRS("Model") = VarModel
SpecsRS.Update
SpecsRS.Close
Set SpecsRS = nothing
%>
<p>
</body>
</html>
Keith Caselman
Caselman's Studio
164 Terry St.
Farmington, AR 72730
Message #2 by Kevin D Riggs <kevin.riggs@p...> on Tue, 09 May 2000 12:06:55 -0400
|
|
Keith,
A much faster way to insert data into the table is to use an SQL "INSERT"
command. I assume you meant to set SpecsRS("Notes") equal to varNotes
rather than varName again. Also, you only need the trailing semicolon if
you are inserting into an Access database. If you are using an SQL Server
database, you don't have to put the semicolon after the end parenthesis.
To use your example below, use the following code.
>>>>>>>>>>>>>>>Code
Snippet<<<<<<<<<<<<<<<<<<
set SpecsRS=Server.CreateObject("ADODOB.Command")
SpecsRS.ActiveConnection = "DSN=cramalot;UID=web;PWD=2673560;3,3"
sqltext = "INSERT INTO Specs (Name, Notes, Model) VALUES ('" & varName &
"', '" & varNotes & "', '" & varModel & "');"
SpecsRS.Execute sqltext
>>>>>>>>>>>>>>>>End
Snippet<<<<<<<<<<<<<<<<<
One of the reasons to use this method is that is only opens the database
once everything is in place and the connection only stays open long enough
for the data to be inserted into the database. When you use the older
".Open", ".AddNew" and ".Update" methods, you leave the database open
longer, tieing up more server resources.
Also, I've found that I usually want to send a Response.Write message back
to my users AFTER inserting the data so that I know that if the user saw
the message, then his data IS in the database. If the code hoses up during
the database execution, he'll know it because he won't see the message that
his data has been entered into the database correctly.
>
> set SpecsRS=Server.CreateObject("ADODB.recordset")
> sqltext = "SELECT * FROM Specs;"
> SpecsRS.open sqltext, "dsn=Cramalot; uid=web; pwd=2673560;3,3"
>SPecsRS.AddNew
> SpecsRS("Name") = VarName
> SpecsRS("Notes") = VarName
> SpecsRS("Model") = VarModel
> SpecsRS.Update
>
> SpecsRS.Close
> Set SpecsRS = nothing
KD
Kevin D Riggs
kevin.riggs@p...
Senior Network Administrator & Webmaster
Rhea County
Board of Education
http://www.rhea.k12.tn.us/
http://www.rheacounty.org/
Message #3 by "Ken Schaefer" <ken.s@a...> on Wed, 10 May 2000 10:36:54 +1000
|
|
I think your problem is that you are opening a Forward Only firehose cursor.
This is caused because you have put the 3, 3 inside the connection string.
Try:
SpecsRS.open sqltext, "dsn=Cramalot; uid=web; pwd=2673560", adOpenDynamic,
AdLockOptimistic, adCmdText
Also, ditch the "magic numbers" and use the constants - you'll thank
yourself later when it comes to debugging (unless you've memorised them, but
I'm sure you have better things to do :-))
Cheers
Ken
>
> -----Original Message-----
> From: Keith Caselman
> Sent: 09 May 2000 05:24
> To: support@w...
> Subject: Can't AddNew
>
>
> I am trying to add to a SQL Database, I have read the data from it may
> times
> in may different ways, but I can't seem to add a record to it. I am
> getting
> the Request.Forms to Response.Write but when I try to add to the database
> I
> get the error "ADODB.Recordset error '800a0cb3'
>
> The operation requested by the application is not supported by the
> provider.
>
> /Insert/Specs/handler_for_insert_asp.asp, line 39 "
>
> Below is the HTML and VBScript. I have granted the User "WEB" all rights
> to
> the database and tabel and the username and password works fine on other
> pages. If you have any ideas, thanks ahead of time.
>
> <html>
>
> <head>
> <meta http-equiv="Content-Language" content="en-us">
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
> <meta name="ProgId" content="FrontPage.Editor.Document">
> <title>Handler for Insert</title>
> </head>
>
> <body>
>
> <p>Handler for Insert_Specs.asp</p>
> <%
> dim name
> dim Notes
> dim Model
>
> VarName = Request.Form("FName")
> VarNotes = Request.Form("FNotes")
> VarModel = Request.Form("FModel")
>
> Response.write (VarName)
> Response.write "<p>"
> Response.write (VarNotes)
> Response.write "<p>"
> Response.write (VarModel)
> Response.write "<P>If you See three entries above, you know the varibles
> are being passed."
> Response.write "<HR>"
>
> dim SpecsRS
>
> set SpecsRS=Server.CreateObject("ADODB.recordset")
> sqltext = "SELECT * FROM Specs;"
> SpecsRS.open sqltext, "dsn=Cramalot; uid=web; pwd=2673560;3,3"
> SPecsRS.AddNew
> SpecsRS("Name") = VarName
> SpecsRS("Notes") = VarName
> SpecsRS("Model") = VarModel
> SpecsRS.Update
>
> SpecsRS.Close
> Set SpecsRS = nothing
>
>
> %>
>
>
> <p>
>
>
>
> </body>
>
> </html>
>
> Keith Caselman
> Caselman's Studio
> 164 Terry St.
> Farmington, AR 72730
|
|
 |