|  | การอ่าน access มาพิมพ์ |  | 
| ข้อควรทราบ | 
| 
 | 
| อ่านข้อมูลจากแฟ้มของ Ms Access 97 มาพิมพ์ | 
| ตัวอย่างชุดนี้ไม่มีอะไรมาก เพียงแสดงให้เห็นการเรียกข้อมูลจากแฟ้ม MDB มาแสดงเท่านั้น แต่เมื่อท่านดูเข้าใจแล้ว ก็ลองนำไปเปลี่ยนโครงสร้างแฟ้มดูสิครับ ข้อมูลในแฟ้มนี้มี 12 ระเบียน โปรแกรมจะอ่านข้อมูลมาแสดงทั้งหมด ท่านสามารถ Download แฟ้ม std9701.mdb ที่นี่ | 
| ตัวอย่างคำสั่ง | ตัวอย่างผลลัพธ์ | 
| <%
   thaialldbaccess97="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath(mBaseDir & "/std9701.mdb")
   Set rec = Server.CreateObject("ADODB.Recordset")
   sql = "select * from student"
   rec.Open sql, thaialldbaccess97
%>
<html><head><title>print all data</title></head>
<body bgcolor="#ffffff">
<%
   rec.MoveFirst
   do while Not rec.eof
      response.write( rec("idstd") &"-"& rec("name") &"-"& rec("score") &"<br>" )
      rec.MoveNext
   loop
%>
</body></html>
 | 4200001-บุรินทร์ รุจจนพันธุ์-65 4200002-ทรรศนีย์ ไชยชนะ-94 4200003-วิเชพ ใจบุญ-78 ... 4200012-ต๊อง ศิษย์ฉ่อย-53 | 
| พิมพ์ข้อมูลในตารางให้เป็นระเบียน และเลือกข้อมูลได้ | 
| แสดงการเขียน ASP ร่วมกับการเขียน ตาราง และทำการเลือกข้อมูล ซึ่งสังเกตุได้จากส่วนของ SQL SQL ย่อมาจาก Structure Query Language ซึ่ง SQL ยังมีความสามารถทั้งเพิ่มลบ และแก้ไขได้ ใช้ได้ดีมาก ข้อมูลที่เตรียมไว้มี 12 ระเบียน แต่เมื่อแสดงผลจะเหลือ 9 เพราะคนที่ได้คะแนนมากกว่า 60 มีเพียง 9 คน ท่านสามารถ Download แฟ้ม std9701.mdb ที่นี่ | 
| ตัวอย่างคำสั่ง | ตัวอย่างผลลัพธ์ | 
| <%
   thaialldbaccess97="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath(mBaseDir & "/std9701.mdb")
   Set rec = Server.CreateObject("ADODB.Recordset")
   sql = "select * from student where score > 60"
   rec.Open sql, thaialldbaccess97
%>
<html><head><title>choose data</title></head>
<body bgcolor="#ffffff">
<%
   i = 1
   rec.MoveFirst
   response.write( "<table widht=100% border=1>" )
   do while Not rec.eof
      response.write( "<tr>" )
      response.write("<td bgcolor=#ffffff>" & i & "</td>" )
      response.write("<td bgcolor=#ffffdd>" & rec("idstd") & "</td>" )
      response.write("<td bgcolor=#ffffdd>" & rec("name") & "</td>" )
      response.write("<td bgcolor=#ffddff>" & rec("score") & "</td>" )
      response.write( "</tr>" )
      rec.MoveNext
      i = i + 1
   loop
   response.write( "</table>" )
%>
</body></html>
 | ตัวอย่างเป็นตาราง ดูเป็นระเบียน พร้อมมีเลขลำดับของระเบียนให้ด้วย Click ที่นี่ดูผลลัพธ์ | 
| คำนวณ Max, Min, Avg แล้วพิมพ์ | 
| แสดงการนำ Score มาคำนวณ และแสดงตัวอย่างการใช้ IF เพื่อตัดสินใจ ท่านสามารถ Download แฟ้ม std9701.mdb ที่นี่ | 
| ตัวอย่างคำสั่ง | ตัวอย่างผลลัพธ์ | 
| <%
   thaialldbaccess97="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath(mBaseDir & "/std9701.mdb")
   Set rec = Server.CreateObject("ADODB.Recordset")
   sql = "select * from student where score > 60" 
   rec.Open sql, thaialldbaccess97
%>
<html><head><title>choose data</title></head>
<body bgcolor="#ffffff">
<%
   max=0
   min=999
   tot=0
   i = 1
   rec.MoveFirst
   response.write( "<table widht=100% border=1>" )
   do while Not rec.eof
      response.write( "<tr>" )
      response.write("<td bgcolor=#ffffff>" & i & "</td>" )
      response.write("<td bgcolor=#ffffdd>" & rec("idstd") & "</td>" )
      response.write("<td bgcolor=#ffffdd>" & rec("name") & "</td>" )
      response.write("<td bgcolor=#ffddff>" & rec("score") & "</td>" )
      response.write( "</tr>" )
      tot = tot + rec("score")
      if max < rec("score") then max = rec("score")
      if min > rec("score") then 
         min = rec("score")
      end if
      rec.MoveNext
      i = i + 1
   loop
   response.write( "</table>" )
   response.write( "Max =" & max & "<br>")
   response.write( "Min =" & min & "<br>")
   response.write( "Avg =" & tot/(i-1))
%>
</body></html>
 | ตัวอย่างเป็นตาราง ดูเป็นระเบียน พร้อมมีเลขลำดับของระเบียนให้ด้วย และแสดงการหาค่า max min และ avg Click ที่นี่ดูผลลัพธ์ | 
| แบบฝึกหัด | 
| 
 |