difference between "conn.execute" and "conn.open"

garry_m
garry_m used Ask the Experts™
on
I have made asp forum which is connected to an access database.  Can anyone tell me what is the difference between these two statements?  (Which both work fine coincidentally)  I would like to know out of pure curiosity.  If anyone could enlighted me that would be cool.  Thanks

'open db connection
set objRs = objConn.execute("INSERT INTO...")
'close db connection

and this:

  sql = "SELECT * FROM MESSAGES"
  'open db connection

  set addrecord = server.createobject("adodb.recordset")
  addrecord.open sql, conn, 1, 3
  addrecord.addnew
  addrecord.fields("DATE") = date()
  'add more fields
  addrecord.update
  ' close connection etc.

Because it seems so much simpler to use the sql "insert" text.

Cheers
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You have to open the connection before you can execute it.

conn.execute will execute a specific SQL statement
conn.open tells it where to connect to.

Here's a sample based on what you have:

set objConn = Server.CreateObject("ADODB.Connection")
objConn.open CONNSTRING
set objRs = objConn.execute("INSERT INTO...")


This will work much faster this way than what you post above since you are doing 1 quick insert statement.  Let your SQL do all the work for you.

Author

Commented:
Thanks, you told me just what I needed to hear :)

I have set it the forum just using the SQL "INSERT" statements because it seemed so much simpler.

Thanks again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial