Click to See Complete Forum and Search --> : Developing a Database utilitiy for DML Command Execution


leong61
07-14-2003, 12:26 PM
Below is my code for executing DML but it cannot work. What should I do?:-


aspIndex.htm:-

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>


<p><a href="authorshow.asp">Show data from the
database</a></p>

</body>

</html>


authorshow.asp:-

<%
response.buffer=true
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "Cache-Control", "private"
%>
<html><head><title>authorshow.asp</title>
<meta http-equiv="pragma" content="no-cache"></head>
<body bgcolor="#FFFFFF">
<%
myDSN="DSN=Author;uid=student;pwd=magic"
mySQL="select * from authors where AU_ID<100 order by author"
IDfield="AU_ID"
scriptresponder="authoredit.asp"

set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
howmanyfields=rstemp.fields.count -1
%>
<table border="1">
<tr>
<td valign="top">---</td>
<% 'Put Headings On The Table of Field Names
for i=0 to howmanyfields %>
<td><b><%=rstemp(i).name %></b></td>
<% next %>
</tr>
<% ' Now lets grab all the records
do while not rstemp.eof %>
<tr><td valign="top">
<%my_link=scriptresponder & "?which=" & rstemp(idfield)%>
<a HREF="<%=my_link%>">Edit</a></td>
<% for i = 0 to howmanyfields%>
<td valign="top"><%=rstemp(i)%></td>
<% next %>
</tr>
<%
rstemp.movenext
loop
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</table></body></html>



authoredit.asp:-

<html><head>
<title>authoredit.asp</title></head>
<body bgcolor="#FFFFFF">
<%
' My ASP program that given an AU_ID, allows editing a record

myDSN="DSN=Author;uid=student;pwd=magic"

set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
form_ID=request.querystring("which")

sqltemp="select * from authors "
sqltemp=sqltemp & " where AU_ID=" & form_id

set rstemp=conntemp.execute(sqltemp)


form_auID=rstemp("AU_ID")
form_author=rstemp("Author")
form_year_born=rstemp("Year_Born")

rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
<body>
<form name="myauthor" action="authoreditrespond.asp" method="POST">

<input type="hidden" name="id" value="<%=form_auid%>">

<p>Author ID: <%=form_auid%></p>

<p> Author Name:
<input type="TEXT" name="name" value="<%=form_author%>"></p>

<p> Year Born:
<input type="TEXT" name="year" value="<%=form_year_born%>"></p>

<p> <input type="SUBMIT"> </p>
</form>
</body>



authoreditrespond.asp:-

<HTML><HEAD><TITLE>authoreditrespond.asp</TITLE>
<body bgcolor="#FFFFFF"></HEAD>
<%
on error resume next
form_name=request.form("name")
form_year=request.form("year")
form_ID=request.form("ID")

Set Conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=Author;uid=student;pwd=magic"

' change apostrophe to double apostrophe
form_name=Replace(form_name, "'", "''")
IF instr(lcase(form_name),"<img")>0 THEN
form_name=""
END IF

SQLstmt = "UPDATE authors SET "
SQLStmt = SQLstmt & "Author='" & form_name & "',"
SQLstmt = SQLstmt & "year_born=" & form_year
SQLStmt = SQLStmt & " WHERE AU_ID=" & form_id

Set RS = Conn.Execute(SQLStmt)

If err.number>0 then
response.write "VBScript Errors Occured:" & "<P>"
response.write "Error Number=" & err.number & "<P>"
response.write "Error Descr.=" & err.description & "<P>"
response.write "Help Context=" & err.helpcontext & "<P>"
response.write "Help Path=" & err.helppath & "<P>"
response.write "Native Error=" & err.nativeerror & "<P>"
response.write "Source=" & err.source & "<P>"
response.write "SQLState=" & err.sqlstate & "<P>"
end if
IF conn.errors.count> 0 then
response.write "Database Errors Occured" & "<P>"
response.write SQLstmt & "<P>"
for counter= 0 to conn.errors.count
response.write "Error #" & conn.errors(counter).number & "<P>"
response.write "Error desc. -> " & conn.errors(counter).description & "<P>"
next
else
response.write "<B>Everything Went Fine. Record is updated now!</b>"
response.write "<br>" & SQLstmt
end if

rs.close
set rs=nothing
Conn.Close
set conn=nothing
%>
</BODY>
</HTML>

olerag
07-14-2003, 01:31 PM
I believe your visiting the wrong theatre. I suggest you submit this to the friendly "servlet" forum at www.java.sun.com.

Along with the code you can also include details about what your trying to accomplish and the specific problem(s) that is/are encountered.

brendandonhue
07-14-2003, 01:37 PM
This is the javascript forum.