Adding a record to access database!

Discussion in 'Databases' started by artfullegac, Jan 9, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I've trie about everything and can't get my code to work.

    <%
    Dim date1
    Dim date
    Dim time
    Dim name
    Dim description
    Dim cost
    Dim status

    date1 = Request.Form("date1")
    date = Request.Form("date")
    time = Request.Form("time")
    name = Request.Form("name")
    description = Request.Form("description")
    cost = Request.Form("cost")
    status = Request.Form("status")

    Dim adoCon
    Dim adoRec
    Dim strSQL

    adoCon = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\mydb.mdb"))

    Set adoRec = Server.CreateObject("ADODB.Recordset")

    adoRec.Open "classes",adoCon,adopenstatic,adlockoptimistic
    This seems to be the problem.</font id="red">

    'adoRec.AddNew

    'adoRec.Fields("date1") = "02/04/2004"
    'adoRec.Fields("date") = "Feb. 04"
    'adoRec.Fields("time") = "10:00pm"
    'adoRec.Fields("name") = "Test"
    'adoRec.Fields("description") = "description"
    'adoRec.Fields("cost") = "$2"
    'adoRec.Fields("status") = "All Welcome!"

    'adoRec.Update

    'adoCon.Close
    Set adoCon = Nothing
    'adoRec.Close
    Set adoRec = Nothing
    %>

    Any assistance you can provide will be appreciated.

    Thanks... Dan
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Why do you want to use a recordset to insert a record?

    You can do something simple like this


    <%

    Dim cnnSimple ' ADO connection
    Dim rstSimple ' ADO recordset
    Set cnnSimple = Server.CreateObject("ADODB.Connection")


    cnnSimple.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\test.mdb"))
    cnnSimple.Execute("insert into tblContact (FirstName,LastName,Email) values ('Joe','blow','[email protected]')")
    cnnSimple.close

    %>

    quote:Originally posted by artfullegac

    I've trie about everything and can't get my code to work.

    <%
    Dim date1
    Dim date
    Dim time
    Dim name
    Dim description
    Dim cost
    Dim status

    date1 = Request.Form("date1")
    date = Request.Form("date")
    time = Request.Form("time")
    name = Request.Form("name")
    description = Request.Form("description")
    cost = Request.Form("cost")
    status = Request.Form("status")

    Dim adoCon
    Dim adoRec
    Dim strSQL

    adoCon = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\mydb.mdb"))

    Set adoRec = Server.CreateObject("ADODB.Recordset")

    adoRec.Open "classes",adoCon,adopenstatic,adlockoptimistic
    This seems to be the problem.</font id="red">

    'adoRec.AddNew

    'adoRec.Fields("date1") = "02/04/2004"
    'adoRec.Fields("date") = "Feb. 04"
    'adoRec.Fields("time") = "10:00pm"
    'adoRec.Fields("name") = "Test"
    'adoRec.Fields("description") = "description"
    'adoRec.Fields("cost") = "$2"
    'adoRec.Fields("status") = "All Welcome!"

    'adoRec.Update

    'adoCon.Close
    Set adoCon = Nothing
    'adoRec.Close
    Set adoRec = Nothing
    %>

    Any assistance you can provide will be appreciated.

    Thanks... Dan
    </blockquote id="quote"></font id="quote">
     
  3. Suspected code was the culprit.

    Fix = adoRec.Open strSQL,adoCon,3,3

    The integer arguments seemed to fix it.

    Thanks... Hope this helps someone.

    Dan
     
  4. Ahhh... I'll lean out my code.

    Thanks again.
     
  5. You can only use the adopenstatic,adlockoptimistic, ... if they are available. These are constants which need to be defined. Usually they are in a specific file, something like adovbcs.inc, which is then included in every page where you want to have these constants available.

    Here is an example file.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page