Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

ADO Execute command

I want to use an ADO "execute" command to add  new records into a talbe,something like this:

'presume I've already got a connection called cn
dim rs as Recordset
set rs=cn.Execute("insert into "Table1" (column1,column2) values ('something','and more')")

This command works fine for adding record to the table. Now, the problem is that I also want to use the rs which I expect to be a valid recordset returned by the command. But I always get a error message saying that "object is closed.".

Would anyone know what the problem is?
0
ChenChen
Asked:
ChenChen
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
because the INSERT statement is not returning a recordset.

a recordset is returned when you do a SELECT * FROM Table1.
0
 
ChenChenAuthor Commented:
Are you sure? emoreau, I thought "Execute" always returned a Recordset object reference if successful.
0
 
Éric MoreauSenior .Net ConsultantCommented:
I am 110 % sure of this.

INSERT, UPDATE and DELETE statements can only return the number of affected records. To retreive this value, pass a long variable as the second parameter of the EXECUTE method.
0
 
Arthur_WoodCommented:
sorry,CheChen,but emoreau is 1000% correct--- Only a SELECT query will return a recordset.

Arthur Wood
0
 
TimCotteeHead of Software ServicesCommented:
Well technically .Execute does ALWAYS return a recordset, however if it is NOT a select statement this is a Closed recordset object which is why the error message "Object is closed" is returned.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now