<%@ Language=VBScript %>

<% Dim BooKName,Price,BookID

Dim lib,rec

Dim path,sql



path = Server.MapPath("/books/Books.mdb")

Set lib = Server.CreateObject("ADODB.Connection")

Set rec = Server.CreateObject("ADODB.Recordset")



sql = "INSERT INTO OrderList (BookID,BooKName,Price)
VALUES (15,'abc',89)"





lib.Provider = "Microsoft.Jet.OLEDB.4.0"



lib.Open path

lib.Execute sql



rec.Close
lib.Close
Set rec = Nothing

Set lib = Nothing

%>


--
Posted via http://dbforums.com

Re: Simple Code by Bob

Bob
Tue Sep 16 05:58:33 CDT 2003

Do you have a question? or are you just looking for comments? If so, see
below:

KakaBoo wrote:
> <%@ Language=VBScript %>
>
> <% Dim BooKName,Price,BookID
>
> Dim lib,rec
>
> Dim path,sql
>
>
>
> path = Server.MapPath("/books/Books.mdb")
>
> Set lib = Server.CreateObject("ADODB.Connection")
>
> Set rec = Server.CreateObject("ADODB.Recordset")

Why create a recordset object that you never use later on? You're wasting
resources and processing time.

>
>
>
> sql = "INSERT INTO OrderList (BookID,BooKName,Price)
> VALUES (15,'abc',89)"
>

Hopefully, the above is really on a single line in your page.

>
>
>
>
> lib.Provider = "Microsoft.Jet.OLEDB.4.0"
>
>
>
> lib.Open path
>
> lib.Execute sql

You should tell ADO what kind of command you are executing (adCmdText) and
how it should be executed (adExecuteNoRecords). You do this in the third
argument of the Execute method:
adCmdText = 1
adExecuteNoRecords = 128
Add them together (it's a bitmask) to get 129.

lib.Execute sql,,129

If you have the ADO constants defined
(http://www.aspfaq.com/show.asp?id=2112), you can do this to make your code
a little more self-documenting:

lib.Execute sql,,adCmdText + adExecuteNoRecords



>
>
>
> rec.Close

This line should cause an error since you never opened the recordset.

> lib.Close
> Set rec = Nothing
>
> Set lib = Nothing
>
Good job cleaning up after yourself.

HTH,
Bob Barrows