Whats wrong with this code ???

Results 1 to 3 of 3

Thread: Whats wrong with this code ???

  1. #1
    Goncalo Proenca Guest

    Default Whats wrong with this code ???

    Hi guys, I&#039m a newbie to ASP ( just started 4 days ago , so dont laugh much plz :) ) and I&#039m trying to WRITE records to a database, and I&#039m using this piece of code :<BR><BR> Dim objConn<BR> NomeBD=server.mappath(".") & "FriendsContatcInfo.mdb"<BR> sConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & NomeBD<BR> Set objConn = Server.CreateObject("ADODB.Connection") <BR> objConn.Open sConnStr<BR> SQLQuery = "SELECT * FROM FRIENDS" <BR> Set objRS = objConn.Execute(SQLQuery)<BR> dim varnome, vartel, varloc<BR> varnome = Request("nome")<BR> vartel = Request("tel")<BR> varloc = Request("locd")<BR>objRS.AddNew<BR>objRS("Name")=v arnome<BR>objRS("StreetAddress")=varloc<BR>objRS(" Zip")=vartel<BR>objRS.Update<BR><BR><BR>varnome, vartel and varlocd are variables that have data from a previous asp file that have a form that ask users what Name, Telephone and Zip/Address that he has to be introduced into the database. The code ( this one, without the objRS.Addnew part and beyhond) works fine if I use a loop while obRS.EOF and response.write to displays the contents of the database.. So it works fine, but I dont understand why it wont write, it says:<BR>Error Type:<BR>ADODB.Recordset (0x800A0CB3)<BR>Object or provider is not capable of performing requested operation.<BR><BR>Can anyone help a newbie here plz ? Thanks in advance

  2. #2
    Join Date
    Dec 1969

    Default RE: Whats wrong with this code ???

    Try this<BR><BR>Dim objConn<BR><BR>NomeBD=server.mappath(".") & "FriendsContatcInfo.mdb"<BR>sConnStr="Provider=Mic rosoft.Jet.OLEDB.4.0;Data Source=" & NomeBD<BR>Set objConn = Server.CreateObject("ADODB.Connection") <BR>objConn.Open sConnStr<BR><BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR>SQLQuery = "SELECT * FROM FRIENDS" <BR>objRS.Open SQLQuery,objConn,3,3

  3. #3
    Join Date
    Dec 1969

    Default Wait, you want to INSERT records?

    If you want to INSERT records into a database then you need to do this:<BR><BR><BR><BR>SQLQuery = "INSERT INTO FRIENDS (varnome, vartel, varloc)"_<BR> & "values (" _<BR> & "&#039" & Request("nome") & "&#039, " _<BR> & "&#039" & Request("tel") & "&#039, " _ & "&#039" & Request("locd") & "&#039)" <BR>conn.Execute SQLQuery <BR><BR><BR>I am going to assume that "varnome, vartel, varloc" are the names of your table datas. If not then change them to match the name of the names you used as your table data titles.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts