Link to home
Start Free TrialLog in
Avatar of vmorales
vmorales

asked on

ASP and Access Database

I have created a simple database, lets call it Members, and a form page using asp. I open a connection to the DSN and Then Open the recordset. After which I try to use the AddNew method and Update Method to add the data to the database. Does not Work. Can some please show me a working example.
Avatar of jedimike
jedimike

here's what I do....reference the recordset by name....

<SCRIPT ID=serverEventHandlersVBS LANGUAGE=vbscript RUNAT=Server>
Sub addnew_onclick()
      News.addRecord
End Sub

Sub del_onclick()
      News.deleteRecord
      News.requery
      News.moveFirst
End Sub

Sub updateRec_onclick()
      News.updateRecord
      News.requery
      News.moveFirst
End Sub
</SCRIPT>
Avatar of vmorales

ASKER

Jedimike,
Forgive me, put I am far from being a programmer "of any type". I am trying to overcome these limitations, therefore I must ask you to provide a more indepth example. If you do not feel that this is worth only 50 points, I will be happy to increase.
Sure:

Here is how you would add the items to a database called Members:
Table called "Members"
Fields called:
"Name","Address","Phone"

On your ASP page, you have input boxes called "name", "address", and "phone".

<%
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.open "Your_DSN","",""  'Your DSN may be "Members"
    sql = "SELECT * FROM Members
    Set RS = Server.CreateObject("ADODB.Recordset")
    RS.Open sql, Conn, 3, 3
%>

<%
RS.AddNew
RS("Name") = request("name")
RS("Address") = request("address")
RS("Phone") = request("phone")
RS.Update
%>

<%
RS.Close
Set RS = nothing
Conn.Close
Set Conn = nothing
%>

Obviously, you must check for errors in their entries..  But, this is how you add a record to a database.

MasseyM,

Thanks, I actually got an answer from a previous question someone else had asked, as a matter of fact, you answered that question for that person. I will be happy to give you the points for this, but may I ask what is the reason behind the following:
I am asking about what's inside the brackets.
    Conn.open "Your_DSN"[,"",""]  'Your DSN may be "Members"
    RS.Open sql, Conn,[ 3, 3 ]
thank you
See previous comment.
See previous comment.
[ ] usually means optional, not required :)

oh yeah, that also mean if you don't need it, don't put it in hehe.

in most cases, conn.open "DSN Name here" should do just fine with unprotected Access tables.
ASKER CERTIFIED SOLUTION
Avatar of MasseyM
MasseyM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial