Storing data in my database

Results 1 to 5 of 5

Thread: Storing data in my database

  1. #1
    Join Date
    Dec 1969
    Posts
    16

    Default Storing data in my database

    Hi,<BR><BR>I have a simple question (which will hopefully lead to a simple answer). How do I get data that&#039s input via a form into my Access 97 table? I have the DSN setup with ODBC and I&#039m only using one table. I also have the form setup and the page saved as a .asp page. But how do I get the data from the form into my database?<BR><BR>Any help is appreciated.<BR><BR>BB

  2. #2
    Join Date
    Dec 1969
    Posts
    3

    Default RE: Storing data in my database

    you should be able to run normal sql statements to insert into the access database like "insert into table ( columnname ) value ( 1234 )" through your asp code..<BR>just create a connection using your dsn and store your sql statement in a string then type<BR>connection.execute sqlstring<BR>hope that helps

  3. #3
    Join Date
    Dec 1969
    Posts
    736

    Default RE: Storing data in my database

    Hey BB.<BR>If this is un-common to you just use the code (re-naming the variables)and hopefully soon you will find this process to be second nature:<BR><BR>First of all get rid of the ADODB DSN Entry. For something as simple as this, it is really not needed! You need 2 files:<BR>1. your form page<BR>2. the script that updates the Data Base<BR><BR>Your form page doesn&#039t need to be an ASP file (have the extention ".asp")<BR><BR>Lets say you have 3 things to add to the database.<BR>1. Person&#039s name<BR>2. Person&#039s age<BR>3. Person&#039s weight<BR><BR>In your form page you will have:<BR>&#060;form action="addToDataBase.asp" method="post"&#062;<BR> &#060;input type="text" name="name" value=""&#062;<BR> &#060;input type="text" name="age" value=""&#062;<BR> &#060;input type="text" name="weight" value=""&#062;<BR> &#060;input type="submit&#062;&#060;input type="reset"&#062;<BR>&#060;/form&#062;<BR><BR>Ok now on to the "addToDataBase.asp" script...<BR>(name this whatever you want to)<BR>The script should look like this:<BR>***************************************** ******<BR>&#060;%<BR>strConnect = "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.mappath("yourdatabase.mdb") & ";"<BR><BR>Dim objRec, objConn<BR>Set objConn = Server.CreateObject("ADODB Connection")<BR>Set objRec = Server.CreateObject("ADODB Recordset")<BR><BR>objConn.Open strConnect<BR>objRec.Open objConn<BR><BR>objRec.AddNew<BR>objRec("Name") = Request.Form("name")<BR>objRec("Age") = Request.Form("age")<BR>objRec("Weight") = Request.Form("weight")<BR>objRec.Update<BR><BR>obj Rec.Close<BR>objConn.Close<BR><BR>Set objRec = Nothing<BR>Set objConn = Nothing<BR>%&#062;<BR><BR><BR>If you want to override each entry simply remove the:<BR>objRec.AddNew<BR><BR><BR>Hope this helps!<BR>-Ian<BR><BR><BR><BR><BR><BR><BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    16

    Default RE: Storing data in my database

    Hey Ian,<BR><BR>Thanks for the reply. What you listed doesn&#039t seem to be too painful (of course by the time I actually try it, I can turn even the smallest thing into a major undertaking! lol) <BR>I saw the line:<BR>strConnect = "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.mappath("yourdatabase.mdb") & ";"<BR>How do I specify which table within the Access database should be updated? Should I be using an Access database that only has one table in it?<BR>Thanks,<BR>BB


  5. #5
    Join Date
    Dec 1969
    Posts
    1,013

    Default RE: Storing data in my database

    &#060;%<BR>&#039This is the input fields from your form<BR><BR>ProjectManager = request.form("ProjectManager")<BR>ManagerPhone = request.form("ManagerPhone")<BR><BR><BR>&#039Conne ct to database & recordset. In this one, I connect to SQL database<BR><BR>Application("ResearchLibrary_CS") = "DRIVER=SQL Server;SERVER=TMSWEB01;DATABASE=ResearchLibrary;UI D=researchlibraryguest;PWD=toyresearchlibrary"<BR> Set query_conn = Server.CreateObject("ADODB.Connection")<BR>query_c onn.open Application("ResearchLibrary_CS") <BR><BR>set rs = Server.CreateObject("ADODB.Recordset")<BR>rs.Curso rType = adOpenKeyset<BR>rs.LockType = 2 &#039 adLockOptimistic<BR>rs.Open "Manager", query_conn , , , 2 &#039adCmdTable<BR><BR>&#039This will help you store information into your database<BR><BR>rs.addnew<BR><BR>rs("ProjectManage r") = ProjectManager<BR>rs("ManagerPhone") = ManagerPhone<BR><BR>rs.update<BR>rs.close<BR>set rs = nothing<BR><BR>%&#062;<BR><BR>I hope it will help.<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
  •