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.
6 1710
The code I'm using is below -
<%
-
'*******************************************************
-
'* ASP 101 Sample Code - http://www.asp101.com/ *
-
'* *
-
'* This code is made available as a service to our *
-
'* visitors and is provided strictly for the *
-
'* purpose of illustration. *
-
'* *
-
'* http://www.asp101.com/samples/license.asp *
-
'* *
-
'* Please direct all inquiries to webmaster@asp101.com *
-
'*******************************************************
-
%>
-
<!-- #include file="adovbs.inc" -->
-
<%
-
Dim CONN_STRING
-
CONN_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\IT_Status.mdb"
-
-
-
' The name of this file so all the links and forms will still
-
' work if you rename it.
-
Dim SCRIPT_NAME
-
SCRIPT_NAME = Request.ServerVariables("SCRIPT_NAME")
-
-
' I use this link a lot so I threw it into a "pseudo-const"
-
' so I don't have to keep typing it.
-
Dim BACK_TO_LIST_TEXT
-
BACK_TO_LIST_TEXT = "<p>Click <a href=""" & SCRIPT_NAME & """>" _
-
& "here</a> to go back to record list.</p>"
-
-
-
'ADD - partly working
-
-
' Declare our standard variables.
-
Dim cnnDBEdit, rstDBEdit ' ADO objects
-
-
Dim strSQL ' To hold various SQL Strings
-
Dim iRecordId ' Used to keep track of the record in play
-
-
' Choose what to do by looking at the action parameter
-
Select Case LCase(Trim(Request.QueryString("action")))
-
Case "add"
-
' Select an empty RS
-
strSQL = "SELECT * FROM tbl_Status WHERE id=0;"
-
-
Set rstDBEdit = Server.CreateObject("ADODB.Recordset")
-
rstDBEdit.Open strSQL, CONN_STRING, adOpenKeyset, adLockOptimistic, adCmdText
-
-
' Add our record and set it's values. You could bounce
-
' into an edit mode here to let people enter the initial
-
' values, but for simplicity I just add the record with
-
' some default values.
-
rstDBEdit.AddNew
-
-
rstDBEdit.Fields("Application_Name").Value = CStr("")
-
rstDBEdit.Fields("Status").Value = CStr("")
-
rstDBEdit.Fields("Comment").Value = CStr("")
-
-
-
rstDBEdit.Update
-
-
' Get the id of the record just added. This might cause
-
' problems with some DB providers, but it works with
-
' the SQL Server our sample runs off.
-
iRecordId = rstDBEdit.Fields("id").Value
-
-
rstDBEdit.Close
-
Set rstDBEdit = Nothing
-
-
Response.Write("<p>Record Id #" & iRecordId & " added!</p>")
-
Response.Write(BACK_TO_LIST_TEXT)
-
'DELETE - this works
-
-
Case "delete"
-
' Get the id to delete
-
iRecordId = Request.QueryString("id")
-
If IsNumeric(iRecordId) Then
-
iRecordId = CLng(iRecordId)
-
Else
-
iRecordId = 0
-
End If
-
-
strSQL = "DELETE FROM tbl_Status WHERE id=" & iRecordId & ";"
-
-
Set cnnDBEdit = Server.CreateObject("ADODB.Connection")
-
cnnDBEdit.Open CONN_STRING
-
-
cnnDBEdit.Execute strSQL, adAffectAll, adExecuteNoRecords
-
-
cnnDBEdit.Close
-
Set cnnDBEdit = Nothing
-
-
-
Response.Write("Record Id #" & iRecordId & " deleted!")
-
Response.Write(BACK_TO_LIST_TEXT)
-
-
-
'EDIT - partly works
-
-
Case "edit"
-
' First of a 2 part process... build a form with the
-
' values from the db.
-
iRecordId = Request.QueryString("id")
-
If IsNumeric(iRecordId) Then
-
iRecordId = CLng(iRecordId)
-
Else
-
iRecordId = 0
-
End If
-
-
strSQL = "SELECT * FROM tbl_Status WHERE id=" & iRecordId & ";"
-
-
Set rstDBEdit = Server.CreateObject("ADODB.Recordset")
-
rstDBEdit.Open strSQL, CONN_STRING, adOpenKeyset, adLockOptimistic, adCmdText
-
-
If Not rstDBEdit.EOF Then
-
%>
-
<form action="<%= SCRIPT_NAME %>?action=editsave" method="post">
-
<input type="hidden" name="id" value="<%= rstDBEdit.Fields("id").Value %>" />
-
<input type="text" name="Application_Name" value="<%= Server.HTMLEncode(rstDBEdit.Fields("Application_Name").Value) %>" /><br />
-
<input type="text" name="Status" value="<%= Server.HTMLEncode(rstDBEdit.Fields("Status").Value) %>" style="height: 22px" /><br />
-
<input type="text" name="Comment" value="<%= Server.HTMLEncode(rstDBEdit.Fields("Comment").Value) %>" /><br />
-
-
<input type="submit" name="Update Database">
-
</form>
-
<%
-
Else
-
Response.Write "Record not found!"
-
End If
-
-
rstDBEdit.Close
-
Set rstDBEdit = Nothing
-
-
Response.Write(BACK_TO_LIST_TEXT)
-
Case "editsave"
-
' Part 2 of 2: Here's where we save the values that the
-
' user entered back to the DB. Again... no error
-
' handling or input checking so ' characters and invalid
-
' values will throw error messages.
-
iRecordId = Request.Form("id")
-
iRecordId = Replace(iRecordId, "'", "''")
-
-
' Date delimiter on this should be changed to # for Access
-
strSQL = "UPDATE tbl_Status SET " _
-
& "Application_Name = '" & CStr(Replace(Request.Form("Application_Name"), "'", "''")) & "', " _
-
& "Status = " & CStr(Replace(Request.Form("Status"), "'", "''")) & ", " _
-
& "Comment = " & CStr(Replace(Request.Form("Comment"), "'", "''")) & ", " _
-
& "WHERE (id = " & iRecordId & ")"
-
-
' If something does throw an error, checking this is
-
' actually a valid command often helps debug.
-
Response.Write strSQL
-
-
Set cnnDBEdit = Server.CreateObject("ADODB.Connection")
-
cnnDBEdit.Open CONN_STRING
-
-
cnnDBEdit.Execute strSQL, adAffectAll, adCmdText Or adExecuteNoRecords
-
-
cnnDBEdit.Close
-
Set cnnDBEdit = Nothing
-
-
Response.Write("<p>Record Id #" & iRecordId & " updated!</p>")
-
Response.Write(BACK_TO_LIST_TEXT)
-
Case Else ' view
-
' Our default action... just lists the records in the DB
-
strSQL = "SELECT * FROM tbl_Status ORDER BY id;"
-
-
Set rstDBEdit = Server.CreateObject("ADODB.Recordset")
-
rstDBEdit.Open strSQL, CONN_STRING, adOpenForwardOnly, adLockReadOnly, adCmdText
-
%>
-
<table border="0" cellspacing="2" cellpadding="2">
-
<thead>
-
<tr>
-
-
<th>Application Name</th>
-
<th>Status</th>
-
<th>Comment</th>
-
<th>Delete</th>
-
<th>Edit</th>
-
</tr>
-
</thead>
-
<tbody>
-
<%
-
Do While Not rstDBEdit.EOF
-
%>
-
<tr>
-
-
<td><%= rstDBEdit.Fields("Application_Name").Value %></td>
-
<td><%= rstDBEdit.Fields("Status").Value %></td>
-
<td><%= rstDBEdit.Fields("Comment").Value %></td>
-
-
<td><a href="<%= SCRIPT_NAME %>?action=delete&id=<%= rstDBEdit.Fields("id").Value %>">Delete</a></td>
-
<td><a href="<%= SCRIPT_NAME %>?action=edit&id=<%= rstDBEdit.Fields("id").Value %>">Edit</a></td>
-
</tr>
-
<%
-
rstDBEdit.MoveNext
-
Loop
-
%>
-
</tbody>
-
<tfoot>
-
<tr>
-
<td colspan="6" align="right"><a href="<%= SCRIPT_NAME %>?action=add">Add a new record</a></td>
-
</tr>
-
</tfoot>
-
</table>
-
<%
-
rstDBEdit.Close
-
Set rstDBEdit = Nothing
-
End Select
-
%>
-
-
<%
-
'********************************
-
' This is the end of the sample!
-
'********************************
-
-
' Feel free to skip this area. (Ignore the man behind the curtain!)
-
' To keep things manageable and working for other visitors, I'm
-
' checking to make sure you don't delete all the records and adding
-
' some to keep at least 2 records in the DB.
-
-
Dim cnnCleanUp, rstCleanUp, iRecordCount
-
-
Set cnnCleanUp = Server.CreateObject("ADODB.Connection")
-
cnnCleanUp.Open CONN_STRING
-
-
strSQL = "SELECT COUNT(*) FROM tbl_status;"
-
-
Set rstCleanUp = cnnCleanUp.Execute(strSQL, , adCmdText)
-
iRecordCount = rstCleanUp.Fields(0).Value
-
rstCleanUp.Close
-
Set rstCleanUp = Nothing
-
-
'Response.Write iRecordCount
-
If iRecordCount <= 2 Then
-
strSQL = "INSERT INTO tbl_Status " _
-
& "(Application_Name, Status,Comment) " _
-
& "VALUES (" _
-
& "'" & Application_Name & "', " _
-
& "'" & Status & "', " _
-
& "'" & Comment & ")"
-
-
-
' Add 2
-
cnnCleanUp.Execute strSQL, adAffectAll, adCmdText Or adExecuteNoRecords
-
cnnCleanUp.Execute strSQL, adAffectAll, adCmdText Or adExecuteNoRecords
-
End If
-
-
cnnCleanUp.Close
-
Set cnnCleanUp = Nothing
-
%>
so which part is giving you trouble?
Jared
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.
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"): -
rstDBEdit.AddNew
-
-
rstDBEdit.Fields("Application_Name").Value = request("application_name")
-
rstDBEdit.Fields("Status").Value = request("status")
-
rstDBEdit.Fields("Comment").Value = request("comment")
-
rstDBEdit.Fields("Time_Stamp").Value = now()
-
-
rstDBEdit.Update
I'm not sure I understand what you are asking, but does this answer your question?
Jared
Jared
Thanks for bearing with me on this.
I've made the changes you suggested.
The errors I get are Edit error - UPDATE tbl_Status SET Application_Name = 'Printers', Status = G, Comment = except Norwich nice, WHERE (id = 24)
-
Microsoft JET Database Engine error '80040e14'
-
Syntax error (missing operator) in query expression 'except Norwich nice'.
-
/systems_statusalert/input3.asp, line 155
Add error - Microsoft JET Database Engine error '80040e21'
-
Field 'tbl_Status.Status' cannot be a zero-length string.
-
/systems_statusalert/input3.asp, line 59
Solved and thanks a series of blond moments at this end.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 -...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |