我正在使用 ASP-classic 制作一个 Web 应用程序,并且我正在尝试更新 Oracle 数据库中的一些值。这是我到目前为止所拥有的。
<script>
function getUpdateHTML()
{
var lockoutcheck;
if (document.getElementById("cellRollLockoutYN").checked)
{
lockoutcheck = "'Y'";
}
else
{
lockoutcheck = "'N'";
}
var updatestring = "RollInventoryViewDev.asp?updatelockout=";
updatestring = updatestring + lockoutcheck + "&updatepatterndepth=";
updatestring = updatestring + document.getElementById("cellProductPatternDepthAvg").value + "&";
updatestring = updatestring + "action=update&sort=roll_id&sortdir=<%=intSortDir%>&id=<%=intRollID%>&iddt=<%=StrRollIdDt%>&seqnum=<%=intRollSeqNum%>&findesc=<%=strRollFinishDescription%>&fincd=<%=strRollFinishCD%>&diam=<%=dblRollDiameter%>&crown=<%=dblRollCrown%>&crownaim=<%=dblRollCrownAim%>&prosrough=<%=intRollProsRoughness%>&peaksrough=<%=intRollPeaksRoughness%>&hardness=<%=intRollHardness%>&metalcd=<%=strRollMetalCD%>&rolltype=<%=strRollType%>&lockout=<%=chrRollLockoutYN%>&depthavg=<%=dblProductPatternDepthAvg%>";
<!--alert("Attempting to Update Record with Lockout: " + lockoutcheck + " and Pattern Depth: " + document.getElementById("cellProductPatternDepthAvg").value);-->
window.open(updatestring,"_self")
}
</script>
<%
'If update selected, then update information
If Request.QueryString("action") = "update" Then
sqlQry = "update tp07_roll_inventory_row set roll_lockout_yn = "&chrUpdateLockout&", product_pattern_depth_avg = "&dblUpdateDepthAvg&" where roll_id = "&intRollID&""%>
<script>alert("<%=sqlQry%>");</script>
<%
' Turn error handling on. If an error is generated, our program will continue to execute and
' the error code will be stored in Err.number.
'On Error Resume Next
' Execute SQL code
Set RS = dbConn.Execute(sqlQry, RowsAffected)
' If an error occured then construct an error message to display to the user
If err<>0 then
message="Unable to Perform Update: "
for each objErr in dbConn.Errors
message = message & objErr.Description & "<br>"
next
' Set message color to red to indicate failure
messageColor = "#DD2222"
' If there was no error then generate a "success" message to display to the user
Else
message="Update Successful: " & rowsAffected & " row(s) updated."
' Set message color to green to indicate success
messageColor = "#22DD22"
End If
Response.write(message)
End If
%>
它会生成一个看起来像update tp07_roll_inventory_row set roll_lockout_yn = 'N', product_pattern_depth_avg = 2.6 where roll_id = 8502;
它的 sql 查询,然后使用 SQL 查询发出警报(只是为了让我知道它的格式正确),打开错误处理然后执行。
如果更新失败,它应该打印“无法执行更新:”和所有错误代码。
现在,它打印“无法执行更新:”但没有打印任何错误代码。而且它肯定无法更新。
编辑:我添加了在单击更新后生成新 URL 的 javascript,所以这里可能有问题。
最初,这个脚本在下面,但现在我已经把它移到上面并注释掉了 On Error, There's a Object required: ''
error on the Set RS = dbConn.Execute(sqlQry, RowsAffected)
line
编辑:这是打开该数据库连接的子例程和打开连接并查询数据库以填充表的数据的代码
%>
<%Sub dbConnect()
Set dbConn=Server.CreateObject("ADODB.Connection")
dbConn.Open "Provider=MSDAORA.1;Password=database;User ID=dba_prd;Data Source=devtm2tcp"
End Sub
Sub dbDisconnect()
dbConn.Close
Set dbConn = Nothing
End Sub
%>
<% '
boolDetailTable = false
Call dbConnect()
sqlQry = "SELECT * FROM TP07_ROLL_INVENTORY_ROW"
if Len(strSort) > 0 then
sqlQry = sqlQry + " ORDER BY " & strSort
if intSortDir <> "1" then
sqlQry = sqlQry + " DESC"
end if
end if
getRS sqlQry
%>