Having trouble adding Recordset into access database through ASP

Discussion in 'ASP General' started by Anand, Feb 6, 2004.

  1. Anand

    Anand Guest

    Hi i am having trouble adding a recordset into the access database,
    the code seems to be working fine it passs and parses through all
    variables just fine without showing any errors and also when i access
    the recordset it displays the results, what the real issue is that the
    entry is not made into the database even though i use the Update
    command and i have also tried the BeginTrans and CommitTrans nothign
    seems to work and i am unable to figure out wats wrong with this
    code.....here is the code below...plz help me out i would really
    apreciate any help...thanks
    Code:
    <%
    ' Connect to database
    Set conn_add = Server.CreateObject("ADODB.Connection")
    'conn_add.mode = 3	'readWrite mode
    conn_add.Open "DSN=semda; UserID=USERIDSTRING; pwd=PWDSTRING"
    
    'conn_add.BeginTrans
    
    if ucase(TypeName(conn_add)) = "CONNECTION" then
    response.Write("CONNECTION MADE!")
    end if
    
    
    If Request.Form("DescShort") = "" Or Request.Form("DescLong") = ""
    Then
    ErrStr = "You didn't fill in all the required fields. Please go back
    and enter all required data."
    Else	'Insert into database
    
    'pulling out max_job
    Set maxJobID = Server.CreateObject("ADODB.Recordset")
    maxJobID.open "Select max(JobID) as max_job from JobList", conn_add
    Do while not maxJobID.eof
    max_job=maxJobID("max_job")
    maxJobID.MoveNext
    Loop
    response.Write("<br>MAX JOB ID IS: "& max_job &"<br>")
    max_job=max_job+1
    maxJobID.Close
    Set maxJobID= Nothing
    
    Set sthRecordset = Server.CreateObject("ADODB.Recordset")
    on error resume next
    
    sthRecordset.open "JobList",conn_add,2,3
    '2,3	adOpenDynamic=2/adOpenKeyset = 1, adLockOptimistic=3
    
    'check for errors
    on error resume next
    If conn_add.Errors.count > 0 Then
    Set objErr = Server.CreateObject("ADODB.Error")
    for each objErr in conn_add.Errors
    If objErr.Number <> 0 Then
    response.Write("Number: " & objErr.Number & "<p>")
    response.Write("Description: " & objErr.Description & "<p>")
    response.Write("Source: " & objErr.Source & "<p>")
    response.Write("SQLState: " & objErr.SQLState & "<p>")
    response.Write("NativeError: " & objErr.NativeError & "<p>")
    End If
    next
    Else
    sthRecordset.AddNew
    response.Write("NEW RECORD ADDED")
    sthRecordset.Fields("JobID") = max_job
    sthRecordset.Fields("DescShort") = Request.Form("DescShort")
    sthRecordset.Fields("DescLong") = Request.Form("DescLong")
    sthRecordset.Fields("TypeID") = Request.Form("TypeID")
    sthRecordset.Fields("PayLow") = Request.Form("PayLow")
    sthRecordset.Fields("PayHi") = Request.Form("PayHi")
    sthRecordset.Fields("ContactName") = Request.Form("ContactName")
    sthRecordset.Fields("Phone") = Request.Form("Phone")
    sthRecordset.Fields("Fax") = Request.Form("Fax")
    sthRecordset.Fields("Email") = Request.Form("Email")
    sthRecordset.Fields("Web") = Request.Form("Web")
    sthRecordset.Fields("Verified") = "No"
    If Request.Form("ExpireDate") = "" Then
    sthRecordset.Fields("ExpireDate") = Date()+30
    Else
    sthRecordset.Fields("ExpireDate") = Request.Form("ExpireDate")
    End if
    sthRecordset.Fields("EnterDate") = Now()
    
    If sthRecordset.Fields("ExpireDate") = "" Then
    ErrStr = "There was a problem converting the expiration date you
    entered. " &_
    "Please go back and make sure you entered a date in the format
    specified."
    response.Write("<br>IN HERE<br>")
    sthRecordset.CancelUpdate
    'conn_add.RollbackTrans
    Else
    sthRecordset.Update
    'conn_add.CommitTrans
    JobID = sthRecordset.Fields("JobID")
    response.Write("<br>NEW RECORD ADDED TOTALY with job id: "& JobID)
    EXPdate = sthRecordset.Fields("ExpireDate")
    response.Write("<br>EXP DATE: "& EXPdate)
    End If
    sthRecordset.Close
    Set sthRecordset = Nothing
    End If
    End If
    %>
    
    Anand, Feb 6, 2004
    #1
    1. Advertising

  2. Anand

    Bob Barrows Guest

    Anand wrote:
    > Hi i am having trouble adding a recordset into the access database,


    Already answered over in .db

    Please do not multipost Anand. This is definitely a database-related
    question so .asp.db was the perfect group in which to post it. Posting it
    here as well did not increase your chances of getting an answer (most of us
    subscribe to both groups). On the contrary, if somebody had taken his time
    to answer it here, only to find that it was already resolved in the other
    group, that person may have been annoyed enough to ignore any future posts
    from you, thereby decreasing your chances of getting help in the future.

    There are times when you will not be sure which group is most appropriate
    (again, this was not one of them), and you will want to post a question to
    both groups. In that situation, you should use the cross-posting technique,
    rather than posting the same message multiple times. To crosspost, put
    a semicolon-delimited* list of the newsgroups to which you wish to post in
    the To: header of your post and post it once. It, and any replies to it,
    will appear in all the newsgroups in your list. So, if I reply in .asp.db,
    my reply will also appear here in .asp.general.

    * ... or whatever delimiter is recognized by your news client

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows, Feb 6, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Naya
    Replies:
    12
    Views:
    594
  2. Joern Schou-Rode
    Replies:
    0
    Views:
    540
    Joern Schou-Rode
    Oct 27, 2008
  3. Tony Johansson
    Replies:
    7
    Views:
    498
    Gregory A. Beamer
    Dec 23, 2009
  4. Tim
    Replies:
    4
    Views:
    133
  5. Hung Huynh
    Replies:
    8
    Views:
    300
    Bob Barrows
    Sep 24, 2003
Loading...

Share This Page