Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is wrong in this code ?
Message
General information
Forum:
Internet
Category:
Active Server Page
Miscellaneous
Thread ID:
00561454
Message ID:
00566161
Views:
31
>>>>Set rstGuestBook = myConn.Execute(mySql)

The ADO connection object execute method returns a *read-only* recordset. You need to open a static, client-side recordset in order to use the AddNew method.

ors.cursorlocation = adUseClient
ors.CursorType = adOpenStatic
ors.LockType = adLockOptimistic


>>>>mySql = "SELECT * FROM GuestBook"

What if your guestbook is large? This query will return the whole table!!! You need to put a where clause on it so it returns an empty recordset that you can add to. Where .F. works for me.

See my page.
http://65.5.211.93:81/artwebdev.asp


Also, when you use the following code

ors.Addnew
...
ors.Update

ADO will, behind the scenes, create a INSERT sql statement and send it to the database.

If you want to clear up the resources you can use ors.ActiveConnection = nothing to create a disconnected recordset.


In regards to the error checking code, I dont have any sample code in front of me, but there is error information in the connection object. Something like this:

on error resume next
ors.execute ...
on error goto 0
If ocn.ErrNumber > 0 Then
process the error
EndIf


-Dave





>Is there any way to check if this operation return any error or it's successful?
>
>
>
>>Set myConn = Server.CreateObject("ADODB.Connection")
>>myConn.ConnectionString = "Your connection string here"
>>myConn.Open
>>mySql = "Your INSERT here"
>>myConn.Execute(mySql)
>>myConn.Close
>>
>>
>>
>>
>>
>>>Guy,
>>>Thank you for your email....
>>>
>>>You main that instead of opening the record set, I'll build the INSERT statment with the fields values in "mySql" and EXCUTE it, Correct ?
>>>
>>>BR
>>>
>>>
>>>>>Hi All,
>>>>>
>>>>>I am getting an error with the following code, can any one advice me what is wrong in this code, the error I get on line "rstGuestBook.AddNew"
>>>>>the aim of this code is, will add a new record to my GuestBook.mdb File.
>>>>>
>>>>>this is the code:
>>>>>
>>>>>Set myConn = Server.CreateObject("ADODB.Connection")
>>>>>myConn.Open "2bs-GuestBook"
>>>>>mySql = "SELECT * FROM GuestBook"
>>>>>Set rstGuestBook = myConn.Execute(mySql)
>>>>>
>>>>>rstGuestBook.AddNew
>>>>>
>>>>>rstGuestBook("Nmae") = Request.Form("txtName")
>>>>>rstGuestBook("Email") = Request.Form("txtEmail")
>>>>>rstGuestBook("Company") = Request.Form("txtCompany")
>>>>>rstGuestBook("Url") = Request.Form("txtUrl")
>>>>>rstGuestBook("Comment") = Request.Form("txtComment")
>>>>>
>>>>>rstGuestBook.Update
>>>>>
>>>>>rstGuestBook.Close
>>>>>Set rstGuestBook = Nothing
>>>>>
>>>>>myConn.Close
>>>>>Set myConn = Nothing
>>>>>
>>>>>Response.Redirect("guest_book_Thanks.html")
>>>>>
>>>>>
>>>>>BR
>>>>
>>>>
>>>>Where's your connection string ?
>>>>
>>>>On a design point of view:
>>>>You should not open a recordset to add a new record. It waste precious ressources for no good reasons.
>>>>You should open you Connection and execute an INSERT query or open a Connection, create a Command object and call a store procedure.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform