• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Getting javascript error while closing ActiveXRecordset object

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am required to insert some data into an access file using javaScript Though the code is inserting the values properly but i am getting an JS Error."operation is not allowed when object is closed"
Here is the code
please suggest how should i close the rs?(you will know "rs" whenyou see the code)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)" />
<meta name="created" content="Wed, 19 Aug 2009 06:14:01 GMT" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />



<script language="JavaScript" >

function getSubmit()
{
var LastName = "Kanujia";
var Firstn = "Nitin" ;

var cn = new ActiveXObject("ADODB.Connection");

//here you must use forward slash to point strait
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:/clientDB.mdb";

var rs = new ActiveXObject("ADODB.Recordset");

var SQL = "INSERT INTO Customers(FirstName, Surname)"
+ " VALUES ( '"+ Firstn +"', '" + LastName +"')";



cn.Open(strConn);

rs.Open(SQL, cn);

//surname.value = rs(0);


rs.Close();

cn.Close();


}
</script>

</head>
<body>
<input type="button" value="submit" onclick="getSubmit()">
</body>
</html>

 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ranch sitterrr", please check your private messages for an important administrative matter.
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, ranch sitterrr,

"operation is not allowed when object is closed" is caused by the rs.close statement. If you want to insert the record, simply use the connection's execute method:



You'll see it's not necessary to use the recordset object. Moreover, If you plan to run the file locally, it's better to save it as ".hta" format, which can bypass the security checking and you can limit the file as single instance, too:


I've zipped the above example together with an Access file in the following link if you want to see the outcome: download page

Cheers,
 
reply
    Bookmark Topic Watch Topic
  • New Topic