Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.

Similar presentations


Presentation on theme: "Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component."— Presentation transcript:

1 Database Connectivity What is ADO

2 What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component ADO is automatically installed with Microsoft IIS ADO is a programming interface to access data in a database

3 Accessing a Database from an ASP Page 1. Create an ADO connection to a database 2. Open the database connection 3. Create an ADO recordset 4. Open the recordset 5. Extract the data you need from the recordset 6. Close the recordset 7. Close the connection

4 1&2. ADO Database Connection Create a DSN-less Database Connection

5 Create an ODBC Database Connection An ODBC Connection to an MS Access Database Open the ODBC icon in your Control Panel. Choose the System DSN tab. Click on Add in the System DSN tab. Select the Microsoft Access Driver. Click Finish. In the next screen, click Select to locate the database. Give the database a Data Source Name (DSN). Click OK.

6 3&4. ADO Recordset To be able to read database data, the data must first be loaded into a recordset. Create an ADO Table Recordset

7 Create an ADO SQL Recordset

8 Extract Data from the Recordset

9 Definitions The ADO Connection Object: The ADO Connection object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database. The ADO Recordset Object :The ADO Recordset object is used to hold a set of records from a database table.

10 Operations List, Add, Update, and Delete Database Records

11 Display the Field Names and Field Values <% set conn=Server.CreateObject("ADO DB.Connection") conn.Provider="Microsoft.Jet.OLE DB.4.0" conn.Open "c:/webdata/northwind.mdb" set rs = Server.CreateObject("ADODB.rec ordset") rs.Open "SELECT * FROM Customers", conn do until rs.EOF for each x in rs.Fields Response.Write(x.name) Response.Write(" = ") Response.Write(x.value & " ") next Response.Write(" ") rs.MoveNext loop rs.close conn.close %>

12 Add a Record to a Table in a Database <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" sql="INSERT INTO customers (customerID," sql=sql & "name,address)" sql=sql & " VALUES " sql=sql & "('" & Request.Form("custid") & "'," sql=sql & "'" & Request.Form("name") & "'," sql=sql & "'" & Request.Form("address") & "')" on error resume next conn.Execute sql, recaffected if err<>0 then Response.Write("No update permissions!") else Response.Write(" " & recaffected & " record added ") end if conn.close %>

13 Update a Record in a Table Update Record <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" cid=Request.Form("customerID") sql="UPDATE customers SET " sql=sql & "name='" & Request.Form("name") & "'," sql=sql & "address='" & Request.Form("address") & "'," sql=sql & " WHERE customerID='" & cid & "'" on error resume next conn.Execute sql if err<>0 then response.write("No update permissions!") else response.write("Record " & cid & " was updated!") end if end if conn.close %>

14 Delete a Record in a Table Delete Record 0 then response.write("No update permissions!") else response.write("Record " & cid & " was deleted!") end if end if conn.close %>

15 Multiple Response.Write's For a large query, this can slow down the script processing time, since many Response.Write commands must be processed by the server.

16 Alternative speed up way The solution is to have the entire string created, from to, and then output it - using Response.Write just once. str = rs.GetString(format,rows,coldel,rowdel,null expr)

17 coldel - the HTML to use as a column- separator rowdel - the HTML to use as a row- separator nullexpr - the HTML to use if a column is NULL

18 "," "," ") %>


Download ppt "Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component."

Similar presentations


Ads by Google