473,414 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

A really Basic ASP to Access problem that has stumped me.

5
Guys I'm sorry to bother you with this but I'm stuck.

I'm trying to do something that OUGHT to be easy and I've looked at numerous examples but got nowhere.

5 fields in an access database table the database is called IT_Status, Table is called tbl_Status ( connection proven and working)
ID ( auto number )
Application_Name ( text )
Status ( Text 1 Char, R, A , G )
Comment ( Text )
Time_stamp ( date and Time )

I want an ASP page to call them all, display them in a tabular layout ( this I can Do ) and allow edit , delete and add. The ID and Time stamp are to be hidden and the latter being auto pop from now() in the perfect world it would also pick up the users details from the browser..

Its been years since I last had to do this sort of thing and only doing it now because the IT department can't....... I've done the rest of the work just this page left.

I've been trying to customise an example from ASP101 samples.
Thanks in advance for any assistance.
Sep 13 '08 #1
6 1710
AlunD
5
The code I'm using is below
Expand|Select|Wrap|Line Numbers
  1. <%
  2. '*******************************************************
  3. '*     ASP 101 Sample Code - http://www.asp101.com/    *
  4. '*                                                     *
  5. '*   This code is made available as a service to our   *
  6. '*      visitors and is provided strictly for the      *
  7. '*               purpose of illustration.              *
  8. '*                                                     *
  9. '*      http://www.asp101.com/samples/license.asp      *
  10. '*                                                     *
  11. '* Please direct all inquiries to webmaster@asp101.com *
  12. '*******************************************************
  13. %>
  14. <!-- #include file="adovbs.inc" -->
  15. <%
  16. Dim CONN_STRING
  17. CONN_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\IT_Status.mdb"
  18.  
  19.  
  20. ' The name of this file so all the links and forms will still
  21. ' work if you rename it.
  22. Dim SCRIPT_NAME
  23. SCRIPT_NAME = Request.ServerVariables("SCRIPT_NAME")
  24.  
  25. ' I use this link a lot so I threw it into a "pseudo-const"
  26. ' so I don't have to keep typing it.
  27. Dim BACK_TO_LIST_TEXT
  28. BACK_TO_LIST_TEXT = "<p>Click <a href=""" & SCRIPT_NAME & """>" _
  29.     & "here</a> to go back to record list.</p>"
  30.  
  31.  
  32. 'ADD - partly working
  33.  
  34. ' Declare our standard variables.
  35. Dim cnnDBEdit, rstDBEdit  ' ADO objects
  36.  
  37. Dim strSQL      ' To hold various SQL Strings
  38. Dim iRecordId   ' Used to keep track of the record in play
  39.  
  40. ' Choose what to do by looking at the action parameter
  41. Select Case LCase(Trim(Request.QueryString("action")))
  42.     Case "add"
  43.         ' Select an empty RS
  44.         strSQL = "SELECT * FROM tbl_Status WHERE id=0;"
  45.  
  46.         Set rstDBEdit = Server.CreateObject("ADODB.Recordset")
  47.         rstDBEdit.Open strSQL, CONN_STRING, adOpenKeyset, adLockOptimistic, adCmdText
  48.  
  49.         ' Add our record and set it's values.  You could bounce
  50.         ' into an edit mode here to let people enter the initial
  51.         ' values, but for simplicity I just add the record with
  52.         ' some default values.
  53.         rstDBEdit.AddNew
  54.  
  55.         rstDBEdit.Fields("Application_Name").Value      = CStr("")
  56.         rstDBEdit.Fields("Status").Value   = CStr("")
  57.         rstDBEdit.Fields("Comment").Value   = CStr("")
  58.  
  59.  
  60.         rstDBEdit.Update
  61.  
  62.         ' Get the id of the record just added. This might cause
  63.         ' problems with some DB providers, but it works with
  64.         ' the SQL Server our sample runs off.
  65.         iRecordId = rstDBEdit.Fields("id").Value
  66.  
  67.         rstDBEdit.Close
  68.         Set rstDBEdit = Nothing
  69.  
  70.         Response.Write("<p>Record Id #" & iRecordId & " added!</p>")
  71.         Response.Write(BACK_TO_LIST_TEXT)
  72. 'DELETE - this works
  73.  
  74.     Case "delete"
  75.         ' Get the id to delete
  76.         iRecordId = Request.QueryString("id")
  77.         If IsNumeric(iRecordId) Then
  78.             iRecordId = CLng(iRecordId)
  79.         Else
  80.             iRecordId = 0
  81.         End If
  82.  
  83.         strSQL = "DELETE FROM tbl_Status WHERE id=" & iRecordId & ";"
  84.  
  85.         Set cnnDBEdit = Server.CreateObject("ADODB.Connection")
  86.         cnnDBEdit.Open CONN_STRING
  87.  
  88.         cnnDBEdit.Execute strSQL, adAffectAll, adExecuteNoRecords
  89.  
  90.         cnnDBEdit.Close
  91.         Set cnnDBEdit = Nothing
  92.  
  93.  
  94.         Response.Write("Record Id #" & iRecordId & " deleted!")
  95.         Response.Write(BACK_TO_LIST_TEXT)
  96.  
  97.  
  98. 'EDIT        - partly works
  99.  
  100.     Case "edit"
  101.         ' First of a 2 part process... build a form with the
  102.         ' values from the db.
  103.         iRecordId = Request.QueryString("id")
  104.         If IsNumeric(iRecordId) Then
  105.             iRecordId = CLng(iRecordId)
  106.         Else
  107.             iRecordId = 0
  108.         End If
  109.  
  110.         strSQL = "SELECT * FROM tbl_Status WHERE id=" & iRecordId & ";"
  111.  
  112.         Set rstDBEdit = Server.CreateObject("ADODB.Recordset")
  113.         rstDBEdit.Open strSQL, CONN_STRING, adOpenKeyset, adLockOptimistic, adCmdText
  114.  
  115.         If Not rstDBEdit.EOF Then
  116.             %>
  117.                     <form action="<%= SCRIPT_NAME %>?action=editsave" method="post">
  118.                 <input type="hidden" name="id" value="<%= rstDBEdit.Fields("id").Value %>" />
  119.                 <input type="text" name="Application_Name" value="<%= Server.HTMLEncode(rstDBEdit.Fields("Application_Name").Value) %>" /><br />
  120.                 <input type="text" name="Status" value="<%= Server.HTMLEncode(rstDBEdit.Fields("Status").Value) %>" style="height: 22px" /><br />
  121.                 <input type="text" name="Comment" value="<%= Server.HTMLEncode(rstDBEdit.Fields("Comment").Value) %>" /><br />
  122.  
  123.                 <input type="submit" name="Update Database">
  124.             </form>
  125.             <%
  126.         Else
  127.             Response.Write "Record not found!"
  128.         End If
  129.  
  130.         rstDBEdit.Close
  131.         Set rstDBEdit = Nothing
  132.  
  133.         Response.Write(BACK_TO_LIST_TEXT)
  134.     Case "editsave"
  135.         ' Part 2 of 2: Here's where we save the values that the
  136.         ' user entered back to the DB.  Again... no error
  137.         ' handling or input checking so ' characters and invalid
  138.         ' values will throw error messages.
  139.         iRecordId = Request.Form("id")
  140.         iRecordId = Replace(iRecordId, "'", "''")
  141.  
  142.         ' Date delimiter on this should be changed to # for Access
  143.         strSQL = "UPDATE tbl_Status SET " _
  144.             & "Application_Name = '" & CStr(Replace(Request.Form("Application_Name"), "'", "''")) & "', " _
  145.             & "Status = " & CStr(Replace(Request.Form("Status"), "'", "''")) & ", " _
  146.             & "Comment = " & CStr(Replace(Request.Form("Comment"), "'", "''")) & ", " _
  147.             & "WHERE (id = " & iRecordId & ")"
  148.  
  149.         ' If something does throw an error, checking this is
  150.         ' actually a valid command often helps debug.
  151.         Response.Write strSQL
  152.  
  153.         Set cnnDBEdit = Server.CreateObject("ADODB.Connection")
  154.         cnnDBEdit.Open CONN_STRING
  155.  
  156.         cnnDBEdit.Execute strSQL, adAffectAll, adCmdText Or adExecuteNoRecords
  157.  
  158.         cnnDBEdit.Close
  159.         Set cnnDBEdit = Nothing
  160.  
  161.         Response.Write("<p>Record Id #" & iRecordId & " updated!</p>")
  162.         Response.Write(BACK_TO_LIST_TEXT)
  163.     Case Else ' view
  164.         ' Our default action... just lists the records in the DB
  165.         strSQL = "SELECT * FROM tbl_Status ORDER BY id;"
  166.  
  167.         Set rstDBEdit = Server.CreateObject("ADODB.Recordset")
  168.         rstDBEdit.Open strSQL, CONN_STRING, adOpenForwardOnly, adLockReadOnly, adCmdText
  169.         %>
  170.         <table border="0" cellspacing="2" cellpadding="2">
  171.         <thead>
  172.         <tr>
  173.  
  174.             <th>Application Name</th>
  175.             <th>Status</th>
  176.             <th>Comment</th>
  177.             <th>Delete</th>
  178.             <th>Edit</th>
  179.         </tr>
  180.         </thead>
  181.         <tbody>
  182.         <%
  183.         Do While Not rstDBEdit.EOF
  184.             %>
  185.             <tr>
  186.  
  187.                 <td><%= rstDBEdit.Fields("Application_Name").Value %></td>
  188.                 <td><%= rstDBEdit.Fields("Status").Value %></td>
  189.                 <td><%= rstDBEdit.Fields("Comment").Value %></td>
  190.  
  191.                 <td><a href="<%= SCRIPT_NAME %>?action=delete&id=<%= rstDBEdit.Fields("id").Value %>">Delete</a></td>
  192.                 <td><a href="<%= SCRIPT_NAME %>?action=edit&id=<%= rstDBEdit.Fields("id").Value %>">Edit</a></td>
  193.             </tr>
  194.             <%
  195.             rstDBEdit.MoveNext
  196.         Loop
  197.         %>
  198.         </tbody>
  199.         <tfoot>
  200.         <tr>
  201.             <td colspan="6" align="right"><a href="<%= SCRIPT_NAME %>?action=add">Add a new record</a></td>
  202.         </tr>
  203.         </tfoot>
  204.         </table>
  205.         <%
  206.         rstDBEdit.Close
  207.         Set rstDBEdit = Nothing
  208. End Select
  209. %>
  210.  
  211. <%
  212. '********************************
  213. ' This is the end of the sample!
  214. '********************************
  215.  
  216. ' Feel free to skip this area. (Ignore the man behind the curtain!)
  217. ' To keep things manageable and working for other visitors, I'm
  218. ' checking to make sure you don't delete all the records and adding
  219. ' some to keep at least 2 records in the DB.
  220.  
  221. Dim cnnCleanUp, rstCleanUp, iRecordCount
  222.  
  223. Set cnnCleanUp = Server.CreateObject("ADODB.Connection")
  224. cnnCleanUp.Open CONN_STRING
  225.  
  226. strSQL = "SELECT COUNT(*) FROM tbl_status;"
  227.  
  228. Set rstCleanUp = cnnCleanUp.Execute(strSQL, , adCmdText)
  229. iRecordCount = rstCleanUp.Fields(0).Value
  230. rstCleanUp.Close
  231. Set rstCleanUp = Nothing
  232.  
  233. 'Response.Write iRecordCount
  234. If iRecordCount <= 2 Then
  235.     strSQL = "INSERT INTO tbl_Status " _
  236.         & "(Application_Name, Status,Comment) " _
  237.         & "VALUES (" _
  238.         & "'" & Application_Name & "', " _
  239.            & "'" & Status & "', " _
  240.         & "'" & Comment & ")"
  241.  
  242.  
  243.     ' Add 2
  244.     cnnCleanUp.Execute strSQL, adAffectAll, adCmdText Or adExecuteNoRecords
  245.     cnnCleanUp.Execute strSQL, adAffectAll, adCmdText Or adExecuteNoRecords
  246. End If
  247.  
  248. cnnCleanUp.Close
  249. Set cnnCleanUp = Nothing
  250. %>
Sep 13 '08 #2
jhardman
3,406 Expert 2GB
so which part is giving you trouble?

Jared
Sep 15 '08 #3
AlunD
5
oops sorry the edit ( starts line 98 ) and add ( starts line 32 ) sections.

It falls over when it tries to send updates / additions to the database.
Sep 15 '08 #4
jhardman
3,406 Expert 2GB
oops sorry the edit ( starts line 98 ) and add ( starts line 32 ) sections.

It falls over when it tries to send updates / additions to the database.
Just looking at the "add" function, the code is just fine. You say it is partly working? What is the trouble? What would you like it to do? Right now it just adds a new blank record to the db. If you want to add values, it needs to say something like this (assuming the user just entered values in fields marked "application_name", "status", and "comment"):
Expand|Select|Wrap|Line Numbers
  1.         rstDBEdit.AddNew
  2.  
  3.         rstDBEdit.Fields("Application_Name").Value      = request("application_name")
  4.         rstDBEdit.Fields("Status").Value   = request("status")
  5.         rstDBEdit.Fields("Comment").Value   = request("comment")
  6.         rstDBEdit.Fields("Time_Stamp").Value = now()
  7.  
  8.         rstDBEdit.Update
I'm not sure I understand what you are asking, but does this answer your question?

Jared
Sep 15 '08 #5
AlunD
5
Jared

Thanks for bearing with me on this.

I've made the changes you suggested.

The errors I get are
Edit error
Expand|Select|Wrap|Line Numbers
  1. UPDATE tbl_Status SET Application_Name = 'Printers', Status = G, Comment = except Norwich nice, WHERE (id = 24)
  2. Microsoft JET Database Engine error '80040e14'
  3. Syntax error (missing operator) in query expression 'except Norwich nice'.
  4. /systems_statusalert/input3.asp, line 155
Add error
Expand|Select|Wrap|Line Numbers
  1. Microsoft JET Database Engine error '80040e21'
  2. Field 'tbl_Status.Status' cannot be a zero-length string.
  3. /systems_statusalert/input3.asp, line 59 
Sep 16 '08 #6
AlunD
5
Solved and thanks a series of blond moments at this end.
Sep 16 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Tim | last post by:
Dear Developers, Firstly, I'm not sure where this post should go so I apologise if this is in the wrong group or area. I'm currently interviewing for a vb.net developer who doesn't mind...
4
by: Darrel | last post by:
I'm really stuck on the concept of using public variables to pass information between usercontrols. I'm pretty sure I'm just flubbing up the syntax. This is what I want: page usercontrol 1 -...
2
by: john in fl | last post by:
Hello, I created an Access97 database wich I just updated to Access 2000. This database had a form that ran a VB event procedure on the current record. This procedure prevented editing if a...
1
by: bruce | last post by:
hi... i have the following test python script.... i'm trying to figure out a couple of things... 1st.. how can i write the output of the "label" to an array, and then how i can select a given...
1
by: ashwah | last post by:
Hi there, I have made a few bit of code in VBA in the past connecting to Access databases but this is my first attempt to connect to an Oracle DB. My code is as follows, and it seems to fall down...
1
by: wildman | last post by:
It's been over 10 years that I don't look at Access. I've been working in asp.net for the last 5 developing intranet sites. Just got a project where we are trying to avoid building an...
2
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
have a problem installing visual basic 2008 express edition web install on vista it completed installing the runtime components successfully and then it says ".net framework 3.5 and the other...
4
by: brock | last post by:
Hi, I do apologize as I'm sure this kind of post is frowned on... But I'm stumped and just need a kick in the right direction... I'm using Visual Basic 2008 Express Edition. My goal: Take...
3
by: ellishnoo | last post by:
Hi there, Please be kind, I have seen some posts where you tell people off for asking without investigating, Im sure most have, anyway I have. Ive only been doin VB 2008 for 7 weeks, and have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.