Page 311 - DCAP408_WEB_PROGRAMMING
P. 311
Unit 14: Database Connectivity
25. </TR> Notes
26. <% Do While Not objRS.EQF %>
27. <TR>
28. <TD><%=objRS(“LastName) %>, <%=objRS(“FirstName”) %></TD>
29. <TD><%=objRS(“Email”) %></TD>
30. <TD><%=objRS(“Username”) %></TD>
31. </TR>
32. <% objRS.MoveNext
33. loop
34. objRS.Close
35. Set objRS = Nothing
36. objConn.Close
37. Set objConn = Nothing
38. %>
39. </Table>
40. </BODY>
41. </HTML>
Explanation of the above program
Line 2 contains the constants that we require. Line 3 connects it to the database. Line 7 to Line 9
create and open the Recordset object that will be used. As we know that if we want to make changes
in the Recordset we cannot use the default lock type. Line 9 specifies the Optimistic Locking. Now
we can add new record. Line 10 invokes AddNew, which creates a new empty record. Line 11 till
Line 14 set all the field values. Finally, line 15 saves the new record to the table using Update. Line
16 resets the cursor to the beginning of the recordset using Movefirst. This starts from the beginning
of the recordset and displaying its contents in the way as stated in the program.
Adding the User to the Table
Lines 8 to Lines 10 check to make sure that all the fields have specified values. If not, a message
describing the problem is printed and a link is provided to go back to the previous page (lines
11 to 13).
Lines 15 to 17 open the recordset. Line 18 check to see whether the current record’s username id
the same as the username entered in the form. If the username are found to be same the message
is printed that is given in line 20. Similarly the email is checked and if it is found to be same a
message given in line 26 is printed. This means that one registration per email.
Notes If any one of the username or email is found to be same the Boolean variable is set
to true (lines 22-30). When this happens the loop is terminated. If both of them are unique
then AddNew is called, the field values are set and update is called.
LOVELY PROFESSIONAL UNIVERSITY 305