By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,797 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,797 IT Pros & Developers. It's quick & easy.

Having trouble adding Recordset into access database through ASP

P: n/a
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
Expand|Select|Wrap|Line Numbers
  1. <%
  2. ' Connect to database
  3. Set conn_add = Server.CreateObject("ADODB.Connection")
  4. 'conn_add.mode = 3    'readWrite mode
  5. conn_add.Open "DSN=semda; UserID=USERIDSTRING; pwd=PWDSTRING"
  6.  
  7. 'conn_add.BeginTrans
  8.  
  9. if ucase(TypeName(conn_add)) = "CONNECTION" then
  10. response.Write("CONNECTION MADE!")
  11. end if
  12.  
  13.  
  14. If Request.Form("DescShort") = "" Or Request.Form("DescLong") = ""
  15. Then
  16. ErrStr = "You didn't fill in all the required fields. Please go back
  17. and enter all required data."
  18. Else    'Insert into database
  19.  
  20. 'pulling out max_job
  21. Set maxJobID = Server.CreateObject("ADODB.Recordset")
  22. maxJobID.open "Select max(JobID) as max_job from JobList", conn_add
  23. Do while not maxJobID.eof
  24. max_job=maxJobID("max_job")
  25. maxJobID.MoveNext
  26. Loop
  27. response.Write("<br>MAX JOB ID IS: "& max_job &"<br>")
  28. max_job=max_job+1
  29. maxJobID.Close
  30. Set maxJobID= Nothing
  31.  
  32. Set sthRecordset = Server.CreateObject("ADODB.Recordset")
  33. on error resume next
  34.  
  35. sthRecordset.open "JobList",conn_add,2,3
  36. '2,3    adOpenDynamic=2/adOpenKeyset = 1, adLockOptimistic=3
  37.  
  38. 'check for errors
  39. on error resume next
  40. If conn_add.Errors.count > 0 Then
  41. Set objErr = Server.CreateObject("ADODB.Error")
  42. for each objErr in conn_add.Errors
  43. If objErr.Number <> 0 Then
  44. response.Write("Number: " & objErr.Number & "<p>")
  45. response.Write("Description: " & objErr.Description & "<p>")
  46. response.Write("Source: " & objErr.Source & "<p>")
  47. response.Write("SQLState: " & objErr.SQLState & "<p>")
  48. response.Write("NativeError: " & objErr.NativeError & "<p>")
  49. End If
  50. next
  51. Else
  52. sthRecordset.AddNew
  53. response.Write("NEW RECORD ADDED")
  54. sthRecordset.Fields("JobID") = max_job
  55. sthRecordset.Fields("DescShort") = Request.Form("DescShort")
  56. sthRecordset.Fields("DescLong") = Request.Form("DescLong")
  57. sthRecordset.Fields("TypeID") = Request.Form("TypeID")
  58. sthRecordset.Fields("PayLow") = Request.Form("PayLow")
  59. sthRecordset.Fields("PayHi") = Request.Form("PayHi")
  60. sthRecordset.Fields("ContactName") = Request.Form("ContactName")
  61. sthRecordset.Fields("Phone") = Request.Form("Phone")
  62. sthRecordset.Fields("Fax") = Request.Form("Fax")
  63. sthRecordset.Fields("Email") = Request.Form("Email")
  64. sthRecordset.Fields("Web") = Request.Form("Web")
  65. sthRecordset.Fields("Verified") = "No"
  66. If Request.Form("ExpireDate") = "" Then
  67. sthRecordset.Fields("ExpireDate") = Date()+30
  68. Else
  69. sthRecordset.Fields("ExpireDate") = Request.Form("ExpireDate")
  70. End if
  71. sthRecordset.Fields("EnterDate") = Now()
  72.  
  73. If sthRecordset.Fields("ExpireDate") = "" Then
  74. ErrStr = "There was a problem converting the expiration date you
  75. entered. " &_
  76. "Please go back and make sure you entered a date in the format
  77. specified."
  78. response.Write("<br>IN HERE<br>")
  79. sthRecordset.CancelUpdate
  80. 'conn_add.RollbackTrans
  81. Else
  82. sthRecordset.Update
  83. 'conn_add.CommitTrans
  84. JobID = sthRecordset.Fields("JobID")
  85. response.Write("<br>NEW RECORD ADDED TOTALY with job id: "& JobID)
  86. EXPdate = sthRecordset.Fields("ExpireDate")
  87. response.Write("<br>EXP DATE: "& EXPdate)
  88. End If
  89. sthRecordset.Close
  90. Set sthRecordset = Nothing
  91. End If
  92. End If
  93. %>
  94.  
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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"
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.