%@ Language=VBScript %> <% option explicit %> <% 'this is a complex example showing selection, adding, updating and deleting 'this demo uses ADO methods in lieu of SQL 'following gets user input information dim lastname dim firstname dim address dim stid lastname = request.form("lastname") firstname = request.form("firstname") address = request.form("address") if request.form("listbox") <> "" then stid = request.form("listbox") elseif request.form("studentid") <> "" then stid = request.form("studentid") end if 'following uses the form inputs to figure out what action to take if request.form("addbtn") = "Add" then addrec elseif request.form("updbtn") = "Update" then updaterec elseif request.form("delbtn") = "Delete" then deleterec end if sub addrec() on error resume next opendb dim sql if lastname <> "" then rs.open "students",conn,3,3 rs.addnew rs.fields("lastname") = lastname if firstname <> "" then rs.fields("firstname") = firstname if address <> "" then rs.fields("address") = address rs.update if err.description <> "" then response.write("
Database Add Error") rs.close sql = "select studentid from students;" rs.open sql,conn,1,1 rs.movelast if not rs.eof then stid = rs.fields("studentid") rs.close else response.write ("Please enter a last name") end if end sub sub deleterec() on error resume next opendb dim sql sql = "select * from students where studentid = " & stid & ";" rs.open sql,conn,3,3 rs.delete rs.close stid = "" if err.description <> "" then response.write("
Database Delete Error") rs.open "students",conn,1,1 rs.close end sub sub updaterec() on error resume next opendb dim sql sql = "select * from students where studentid = " & stid & ";" rs.open sql,conn,3,3 rs.fields("lastname") = lastname if firstname <> "" then rs.fields("firstname") = firstname if address <> "" then rs.fields("address") = address rs.update rs.close if err.description <> "" then response.write("
Database Update Error") rs.open "students",conn,1,1 rs.close end sub %>
<% if stid <> "" then rs.close closedb %>