<%@ Language=VBScript %> <% option explicit %> Simple DB Extraction-Errors

Simple Database Extraction - Error Handling

 

<% 'the following hides errors... on error resume next 'this is how error processing can be used to make life simpler Set conn = Server.CreateObject("ADODB.Connection") dim fname fname = server.mappath("students.mdb") connstr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & fname conn.open connstr,"","" Set rs = Server.CreateObject("ADODB.Recordset") ' Substitute in form parameters into the query string 'following is a big error... sql = "select * from studddents;" rs.Open sql, conn, 1, 1 'following finds the error and lets you know about it... if Err.Description <> "" then response.write("

Error Detected: " & Err.Description & "

") else do while not rs.eof 'the following is an error...but the code skips it and keeps on going... Response.Write (rs.fields("lasttname")) response.write (", ") Response.Write (rs.fields("firstname")) response.write ("

") 'Close the loop iterating records if Err.Description <> "" then response.write("

Error Detected: " & Err.Description & "

") rs.MoveNext Loop end if rs.Close set rs = Nothing set conn = Nothing %>