1 / 10

動態網頁設計 ASP & 資料庫應用

動態網頁設計 ASP & 資料庫應用. 講師:梁家豪 E-Mail: u8855043@ccu.edu.tw. ASP 與資料庫連結步驟. 步驟一:建立一個 Connection 物件 Set conn = Server.CreateObject(“ADODB.Connection”) 步驟二:開啟資料庫之間的連結 driver = “driver={Microsoft Access Driver (*.mdb)};” path = Server.MapPath(“address.mdb") conn.Open driver & path

brad
Télécharger la présentation

動態網頁設計 ASP & 資料庫應用

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 動態網頁設計 ASP & 資料庫應用 講師:梁家豪 E-Mail: u8855043@ccu.edu.tw

  2. ASP與資料庫連結步驟 • 步驟一:建立一個Connection物件 • Set conn = Server.CreateObject(“ADODB.Connection”) • 步驟二:開啟資料庫之間的連結 • driver = “driver={Microsoft Access Driver (*.mdb)};” • path = Server.MapPath(“address.mdb") • conn.Open driver & path • 步驟三:執行SQL語法 • Set rs = conn.Execute(sql) • rs 為一 Recordset 物件

  3. Recordset 物件 ↓欄位 • 資料欄位的集合構成資料錄,資料錄的集合構成資料表 ←標題列 ←資料錄 ←資料錄 ←資料錄

  4. Recordset 物件 • rs(“欄位名稱”) – 印出資料 • rs.EOF – 目前資料錄是否移過最後一筆 • rs.BOF – 目前資料錄是否移過最前一筆 • rs.MoveNext – 資料錄往下移一筆 • rs.MovePrevious – 資料錄往前移一筆 • rs.MoveFirst – 資料錄移至最前端 • rs.MoveLast – 資料錄移至最後端

  5. 印出資料 • 利用While-Wend及EOF的判斷方式,將所有資料從rs物件中印出。 • While NOT rs.EOF Response.write rs(“fldName”) &”<br>” rs.MoveNextWend • 印出資料時,可以使用HTML表格的方式來排版,增加資料的可閱讀性,<table>代表表格整體,<tr>代表一列資料,<td>代表一欄資料

  6. ASP與資料庫連結方法二 • 此方式不使用conn.Execute的方式開啟資料錄,因為conn.Execute開啟的資料錄只能Forward-Only • 方式如下: • Set conn = Server.CreateObject(“ADODB.Connection”) • driver = “driver={Microsoft Access Driver (*.mdb)};” • path = Server.MapPath(“address.mdb") • conn.Open driver & path • Set rs = Server.CreateObject(“ADODB.Recordset”) • sql = “select * from tblAddress” • rs.Open sql, conn, rs類型, 鎖定類型

  7. rs.Open 解說 • Recordset 類型 • 鎖定類型(可省略)

  8. 分頁瀏覽 • rs.PageSize – 設定每頁資料錄筆數 • rs.AbsolutePage – 目前所在絕對頁數 • 印出資料,則使用For-Next的方式 • For I = 1 to rs.PageSize Response.write rs(“fldName”) &”<br>” rs.MoveNext if rs.EOF then Exit forNext

  9. 分頁瀏覽 • rs.PageCount – 目前所在頁數 • rs.RecordCount – 有幾筆資料數 • 上下頁的換頁 • 如果位於第一頁,不提供第一頁及上一頁 • 如果位於最後一頁,不提供下一頁及最後一頁 • 其他,則全部提供

  10. 資料的新增修改刪除 • 資料新增 • rs.AddNew ‘要求新增一筆資料rs(“fldName”) = 值 ’設定資料的內容rs.Update ‘更新寫入至資料庫 • 資料修改 • rs(“fldName”) = 新值 ‘設定新資料rs.Update ‘更新寫入至資料庫中 • 資料刪除 • 利用SQL語法,直接刪除

More Related