我正在使用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 Query进行警报(只是我知道它的格式正确),打开错误处理然后执行。
如果无法更新,则应打印“无法执行更新:”以及所有错误代码。
目前,它打印“无法执行更新:”,但不会打印任何错误代码。它肯定无法更新。
编辑:我添加了点击更新后生成新网址的javascript,所以这里可能存在问题。
最初,此脚本位于下方,但现在我已将其移至上方并注释掉On Error,Object required: ''
行上出现Set RS = dbConn.Execute(sqlQry, RowsAffected)
错误
编辑:这是打开该数据库连接的子例程,以及打开连接并查询数据库以填充表的数据的代码
%>
<%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
%>
答案 0 :(得分:1)
将您的代码更改为此代码并查看是否看到任何错误:我在邮件中添加了err.description
。
<%
' 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
Call dbConnect()
Set result = dbConn.Execute(sqlQry, rowsAffected)
' If an error occured then construct an error message to display to the user
If err.Number <> 0 then
message="Unable to Perform Update: "
'get the error description from err object
message = message & Err.Description & "<br>"
'get errors, if any, from connection object
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 Succssfull: " & rowsAffected & " row(s) updated."
' Set message color to green to indicate success
messageColor = "#22DD22"
End If
Call dbDisconnect()
Response.Write(message)
End If
%>