|
-
Jun 26th, 2006, 01:50 AM
#1
Thread Starter
Lively Member
ASP: Try and Catch
Is there any examples on using Try and Catch statement in ASP??
-
Jun 26th, 2006, 02:07 AM
#2
PowerPoster
Re: ASP: Try and Catch
what are you trying to do with them ..?
edit: these are .Net stuff??
Anyway, if its error handling its basically ..
On Error Resume Next '// ERROR CHECKING
If err <> 0 Then '// ERROR OCCURRED
On Error Goto 0 '// Clear Errors
On Error Resume Next '// NEW ERROR CHECKING
Last edited by rory; Jun 26th, 2006 at 02:11 AM.
-
Jun 26th, 2006, 03:04 AM
#3
Thread Starter
Lively Member
Re: ASP: Try and Catch
I want to use Try and Catch to catch the error in my ASP code. Im trying to insert and update data into Access database. I want the program to throw exception instead of displaying the error page.
Here's my code:
<%
Dim adoCon
Dim rs
Dim strSQL
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db1.mdb")
'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=guestbook"
'Create an ADO recordset object
Set rs = Server.CreateObject("ADODB.Recordset")
<script type="text/javascript">
var txt=""
function message()
{
try
{
strSQL = "insert into course values ('"+request.form("dNAME")+"','"+request.form("cNAME")+"','"+request.form("cNO")+"');"
}
catch(err)
{
txt="error occured"
}
}
</script>
'Open the recordset with the SQL query
rs.Open strSQL, adoCon
%>
The connection code all work correctly except for the javascript. It will show error when I submit data. Maybe is the arrangement of the data has got problem.
Any idea?
-
Jun 26th, 2006, 03:21 AM
#4
PowerPoster
Re: ASP: Try and Catch
The only Error checking for ASP is what I posted above.
Otherwise:
1-you have to open and close the ASP tags for javascript to work ..
2-you cant pass a javascript variable to ASP, only the other way around
Here is a way to do it ..
Code:
<%
Option Explicit
Dim objCon, strSQL
Dim dNAME, cNAME, cNO
On Error Resume Next
dNAME = request.form("dNAME")
cNAME= request.form("cNAME")
cNO= request.form("cNO")
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("./db1.mdb")
strSQL = "insert into course values ('" & dNAME & "','" & cNAME & "','" & cNO & "');"
objCon.Execute (strSQL)
Set objCon = Nothing
If err = 0 Then
Response.Write "Record Added"
Else
Response.Write "Error Occurred<br>" & err.Description
End If
%>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|