Erro in recordset.AddNew()

THIS IS MY CODE AND I HAVE THE
ERROR MESSAGE AT THE END. IT SEEMS THE
rs.AddNew IS NOT RECOGNIZED.

I ALSO TRIED
rs.AddRecord() BUT GOT THE SAME ERROR.

thanks

Code
------
<% @LANGUAGE=JScript %>
<!-- METADATA TYPE="typelib" FILE="c:\Program Files\Common Files\System\ado\msado15.dll" -->

<%
var oConn;
var rs;
var name
oConn = Server.CreateObject("ADODB.Connection");
rs = Server.CreateObject("ADODB.Recordset");
try{    
  oConn.Open ("myDB");
   }
  catch (e)
{
// check for errors
Response.Write ("Error in Connecting to the database - data source")
Response.end
}
rs.CursorLocation = adUseClient;

try{    
   rs.Open ("Client", oConn, adOpenForwardOnly, adLockReadOnly, adCmdTable);
  }
  catch (e)
{
// check for errors
Response.Write ("Error in Opening the table in the database")
//Response.end
}

rs.AddNew();  //THIS IS LINE 32 WHERE THE ERROR IS REPORTED

 rs("fname") = "John";
rs.update();

%>

Error Message
-----------------------
Microsoft JScript runtime error '800a01b6'
Object doesn't support this property or method
/myfile/a.asp, line 32
yassin092898Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
robbertConnect With a Mentor Commented:
Hi yassin!

There are several types of recordsets. You are currently using "adOpenForwardOnly", which means that the RS is read only, and you can move forward only. This is a fast method for listing results.

Instead, use "adOpenKeyset".

Regards, Robert
0
 
SiteSeeCommented:
You need to have the Virtual include to adojavas referenced at the very top of your script...
<%@ LANGUAGE = "JavaScript" %>
<!-- #Include file="adojavas.inc"  -->
0
 
SiteSeeCommented:
or...
 <%@ LANGUAGE = "JScript" %>
.... in your case
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
yassin092898Author Commented:
<%@ LANGUAGE = "JScript" %>
<!--#include file="adojavas.inc"-->

I have both lines at the top but it still complaining about
 rs.addNew(); call
0
 
SiteSeeCommented:
I actually know very little about JScript...(despite it's similarity to VBScript)..
here's the same kind of script in VBScript...and it works..

<%@ LANGUAGE = "VBScript" %>
<!-- #Include file="adovbs.inc"  -->

<%
set cn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")

strConnect = "dsn=YOURDSN"

cn.Open strConnect

Set rs.ActiveConnection = cn
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Source = "TABLENAME"
rs.Open

rs.AddNew
      rs.Fields("AssociateName") = Request.Form("AssociateName")
      rs.Fields("AssociateContact") = Request.Form("AssociateContact")
      rs.Fields("AssociateUrl") = Request.Form("AssociateUrl")
      rs.Fields("AssociateMailingAddress") = Request.Form("AssociateMailingAddress")
      rs.Fields("AssociateCity") = Request.Form("AssociateCity")
      rs.Fields("AssociateState") = Request.Form("AssociateState")
      rs.Fields("AssociateCountry") = Request.Form("AssociateCountry")
      rs.Fields("AssociateZip") = Request.Form("AssociateZip")
      rs.Fields("AssociateEmail") = Request.Form("AssociateEmail")
      rs.Fields("AssociatePhone") = Request.Form("AssociatePhone")
      rs.Fields("AssociatePassword") = Request.Form("AssociatePassword")
rs.Update

Set rs = cn.Execute("YOUR_DB_QUERY_TO_RETURN_NEW_ID#")

%>

  <%
rs.close

cn.close

  %>

---------------------------
Make sense...??...just change your FormFieldValues

Steve
0
 
SiteSeeCommented:
Also, you can do Response.writes anywhere in the <body> that you want to display values from the form submission...
like this:

<%response.write Request.Form ("AssociateName")%>

-------------------------


and then do this at the very bottom of the page...:
 <%
rs.close

cn.close

  %>

</body>
</html>
--------------------


Steve
0
 
yassin092898Author Commented:
Steve thanks for the comment, I know VBScrit and I am trying to do te same with JScript.
0
 
SiteSeeCommented:
This doesn't seem complete:

rs.addNew();

....don't you need to have the object you want to add within the parentheses()??

....for instance, this is a jscript select query I have in one of my pages......
<%@ LANGUAGE=JScript %>
<!--#include file="adojavas.inc"-->
<%
// the line below is the connection string
//dbConnStr="DBQ="+Server.MapPath("/YOURFOLDER/YOURDATABASE.mdb")+";driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;";
dbConnStr="DBQ=YOURPATH\\YOURFOLDER\\YOURDATABASE.mdb;driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;";

// do some basic input error checking first. If the user tries to access this form w/o using the search form,
// send them to the error page
theTitle= new String(Request.QueryString("Title"));
theCategoryName= new String(Request.QueryString("CategoryName"));
theAuthorLastName= new String(Request.QueryString("AuthorLastName"));
thePage=Request.QueryString("p");
// if (!Inputs()) {
//      Response.Redirect("error.asp");
//      Response.End();
// }

// open the db, get the banner record, get the current results - make sure everything is OK before
// displaying the page, otherwise redir to the error page
conn=Server.CreateObject("ADODB.Connection");
res=Server.CreateObject("ADODB.Recordset");
conn.Open(dbConnStr);
res.Open("SELECT * FROM books WHERE (Title LIKE '"+theTitle+"' OR CategoryName LIKE '"+theCategoryName+"' OR AuthorLastName LIKE '"+theAuthorLastName+"') ORDER BY Title",conn, adOpenStatic, adLockReadOnly);
res.PageSize=5;
%>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<html>

-------------------------
Note that the sql query  and other objects are all INSIDE the parentheses...

maybe this is the problem??

Steve
0
All Courses

From novice to tech pro — start learning today.