130 likes | 141 Views
In today's lab, we will create a database and a simple data form to add members to the member table. We will use ADO objects to establish a database connection, create a recordset object, and save the registration date and IP number of each guest.
E N D
Today, We are going to finish our password files and add members to the member table in our database Objectives: Creating the database to be used in lab application Designing a simple data form Defining Road Map Using some ADO Objects Understanding Connection Variables How to create database connection How to create recordset object Using some ADO RecordSet Methods AddNew Update Saving registration date of a guest Taking IP number of a guest
a Database Application • What are we going to do? • Design/Create your database • a. Access File Name: db341.mdb • b. Table Name: member • c: Field Names: member(memID, memName, memSurname, memAddress) • C) Design your pages and road map • ADD: 1-dataadd.asp 2-dataadddb.asp • We are going to record our members to a database • Database in Access Access File Name: db341.mdb
ADDING A RECORD C) Web Pages and the road map ADD: 1-dataadd.asp 2-dataadddb.asp Name: Your record has been entered successfully Surname: Address: Submit dataadddb.asp dataadd.asp
ADDING A RECORD INSERT / FORM Name Address Sexuality Hobbies Select from a list Which one? PAGE DESIGN IN FRONTPAGE Dataadddb.asp dataadd.asp
ADDING A RECORD- dataadd.asp dataadddb.asp These lines must be deleted It is better to change according to the related field name of the table
ADDING A RECORD- dataadddb.asp • Create Connection (bağlantı kur –dbbaglanti.txt) • ‘Process (aspekle.txt) • Close Connection (bağlantı kapat –dbbaglanti.txt) <% set conn341 = Server.CreateObject("ADODB.Connection") conn341.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db341.mdb")) ‘ASPEKLE.TXT conn341.Close Set conn341 = Nothing %>
It is used to create a database connection Driver MS Access Database DBQ Determines File Position Server.MapPath File name must be local and absolute. But it creates some problems. Server.MapPath converts relative address to a absolute address. ADO requires these 2 information ADDING A RECORD- dataadddb.aspDatabase Connection <% set conn341 = Server.CreateObject("ADODB.Connection") conn341.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db341.mdb")) %>
ADDING A RECORD- dataadddb.aspCreating a RecordSet The recordset object contains a copy of records—all or some. The set of records has a beginning and end. The beginning/The end ismarked by a set of characters, referred to as Beginning of File (BOF) End of File (EOF) Do While Not RecordSet.EOF ‘Do something… RecordSet.MoveNext Loop
ADDING A RECORD - dataadddb.asp Creating a RecordSet – aspekle.txt Set kayitseti = server. CreateObject("ADODB.Recordset") kayitseti.Open "kayit", conn341 , 1 , 3 kayitseti.AddNew kayitseti("kayitTar")=Day(now())& "/" &Month(now())& "/" &Year(now())& " “& FormatDateTime(now(),3) kayitseti("kayitIP")=Request.ServerVariables("REMOTE_ADDR") kayitseti.update kayitseti.close set kayitseti = nothing Response.Write “.........”
ADDING A RECORD - dataadddb.asp Creating a RecordSet – aspekle.txt rs.open “table_name”, connection_name, Cursor_Type, Lock_Type Open it enables the recordset ready in order to access data. Close it closes open recorset object and depended objects on recordset Nothing it releases the connection object rs.close set rs = nothing
ADDING A RECORD - dataadddb.asp Creating a RecordSet – aspekle.txt Create the connection Create the recordset rs1(“memName”) = request.form(“txtmemName”) rs1(“memSurname”) = request.form(“txtmemSurname”) rs1(“memAddress”) = request.form(“txtmemAddress”) rs1(“memRecordDate”) = Day(now()) & “/ ” & Month(now()) & “/ “ & Year(now()) & “ “ FormatDateTime(now(),3) rs1(“memRecordIP”) = Server.RequestVariables(“REMOTE_ADDR”) Adding a Record Close the Recordset Close the Connection