การโปรแกรม ภาษาเอเอสพี (ASP) สำหรับ Dynamic Webpage
เว็บเพจสำรอง (Backup Webpages) : thaiall.com | thaiabc.com
ปรับปรุง : 2551-10-20 (แก้ปัญหา unicode)
มีคำ 2 คำที่ผมศรัทธาคือ Learning by doing และ Teaching by example
จึงทำให้ผมเป็นนักพัฒนาเว็บไซต์ อย่างที่เป็นอยู่ในปัจจุบัน
เอเอสพีคืออะไร (What is ASP?) [wikipedia.org]
เอเอสพี (ASP = Active Server page) และ เอเอสพีดอทเน็ต (ASP.NET = Active Server page .NET) คือ ภาษาโปรแกรมที่ทำงานบนเครื่องบริการเว็บไอไอเอส (IIS = Internet Infomation Service) เป็นภาษาสคริปต์ทำงานฝั่งเครื่องบริการ (Server-Side Script) พัฒนาโดยบริษัทไมโครซอฟท์ โดยมีรากฐานภาษามาจากภาษาเบสิก สำหรับเอเอสพีดอทเน็ตจะต้องทำงานบนดอทเน็ตเฟรมเวิร์ค (Dotnet Framework)
บริษัทไมโครซอฟท์ได้เริ่มพัฒนาเอเอสพีในช่วงเดือนธันวาคม พ.ศ. 2540 (ค.ศ.1997) มากับไอไอเอส 3.0 (IIS = Internet Information Server) สำหรับเอเอสพีรุ่น 1 ถูกมองว่าทำงานได้ล่าช้ากว่าโปรแกรมประเภทเดียวกัน อีก 1 ปีต่อมา บริษัทไมโครซอฟท์ได้เปิดตัวเอเอสพีรุ่น 2 ให้เป็นส่วนหนึ่งของ Option Pack ใน Windows NT4 และ 2 ปีต่อมาไอไอเอสรุ่น 3 ได้เปิดตัวเป็นส่วนหนึ่งของระบบปฏิบัติการวินโดว์ 2000
รุ่นของเอเอสพี (ASP Version)
- ASP รุ่น 1 (ธันวาคม ค.ศ.1997) พร้อมเว็บเซิร์ฟเวอร์ไอไอเอส 3.0 (IIS 3.0)
- ASP รุ่น 2 (กันยายน ค.ศ.1998) พร้อมเว็บเซิร์ฟเวอร์ไอไอเอส 4.0 บนวินโดว์ NT
- ASP รุ่น 3 (พฤศจิกายน ค.ศ. 2000) พร้อมเว็บเซิร์ฟเวอร์ไอไอเอส 5.0 บนวินโดว์ 2000
- ASP+ (ปลาย ค.ศ.2000) เป็นรุ่นทดลองใช้ชื่อว่า ASP+ ต่อมาเปลี่ยนชื่อเป็น ASP.NET
- ASP.NET รุ่น 1 (กุมภาพันธ์ ค.ศ.2002) เปิดตัวพร้อม .NET Framework
- ASP.NET รุ่น 2 เปิดตัว 7 พฤศจิกายน ค.ศ.2005
การแก้ปัญหาภาษาไทยของ .mdb + asp
คุณ Rattakorn Jitsripitaklert ส่งแฟ้ม .mdb ซึ่งมีข้อมูลเป็น unicode ดังภาพ ถ้าอ่านข้อมูลด้วย asp ธรรมดา จะแสดงเป็น ?? ซึ่งเป็นปัญหาคล้ายการใช้ php กับ mysql สำหรับการแก้ปัญหาเมื่อใช้แฟ้ม .asp อ่านข้อมูลมาแสดงอย่างถูกต้อง ทำโดยเพิ่มบรรทัดนี้เป็นบรรทัดแรก
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
...
ASP Free Webhosting
- 7host.com, 1asphost.com
- domaindlx.com, globalweb.com, websamba.com

แนะนำเว็บไซต์ (Web Guides)
- Thaiwbi.com - Passkorn Roungrong (ละเอียด)
- Junpen Sairapan & Rattakorn Jitsripitaklert
- ASPThai.net
- บทความ e-Commerce [ Download ]
- ASP e-Commerce (รวม link)
- W3schools.com (ยกนิ้ว)
- tosdn.com (รวม Script)
- Refdev.com
- Aspfree.com
- Asp101.com
- Aspin.com
- Asp-help.com
- Learnasp.com
- Haneng.com/Lessons_17.asp
- task_password.html
- อ.กิตติภูมิ วรฉัตร
- CodeBank
- หัวข้อใน CD 6 แผ่น
Download :: Shopping Cart

เว็บเกี่ยวกับ ASP (แต่ปัจจุบันหายไปแล้ว .. น่าเสียดายครับ)
- http://builder.customix.net
- http://aspbuilder.webhostme.com
- http://www.ultimateasp.com (ไม่หาย แต่เลิกให้ฟรี)
รหัสต้นฉบับ (Source Code)
1. กระดานข่าว (Webboard)
- สมาชิกได้สิทธิการเป็นสมาชิกทันที
- ลบสมาชิก แล้วจะลบกระทู้ทั้งหมดของสมาชิก
- admin ลบสมาชิก กระทู้ส่วนตอบ และคำถาม
- สืบค้นกระทู้ จากหัวข้อ และรายละเอียดได้
- แสดงจำนวนผู้อ่าน และเขียน แต่ละกระทู้
- เคยทดสอบที่ 7host.com + boardx.mdb
2. select3.asp :: โปรแกรมช่วยนำเสนอข้อมูลจากตารางใน .mdb หรือ .xls
ตัวอย่าง : อ่านข้อมูลผู้มีสิทธิ์สอบ อบต. ลำปาง แบบสืบค้นตามชื่อ หรือเรียงตามนามสกุล (โปรแกรมช่วยเลือกข้อมูลจากตารางใน .mdb ผ่าน URL)
3. ระบบข่าว :: เพิ่ม-ลบ โดยระบบสมาชิก
- โปรแกรมสำหรับบริการ ระบบข่าว (News System) อย่างง่าย
- ปรับให้ใช้กับ Intranet ของจังหวัดลำปาง และบริษัทเอกชนแห่งหนึ่ง
- ชื่อแฟ้ม : dbinfo.mdb, dbnews.mdb, default.asp, ynaddnews.asp
- แสดงวันที่ response.write (Formatdatetime(now(),1))
- ตัวอย่าง http://www.yonok.ac.th/news/default.asp
- ตัวอย่าง http://www.mrsakda.com/report/default.asp
- ตัวอย่าง http://www.ops.go.th/news/default.asp
4. upload.asp :: สำหรับส่งแฟ้มเข้า server
- นำจาก freeaspupload.net มาแก้ไข
- ใช้แฟ้มเดียว หรือส่ง file จากแฟ้มอื่น ก็รับ
คำถาม-คำตอบ
ถาม หนุ่มคนหนึ่ง อยากรู้ชื่อ Directory ในเครื่องบริการของตน
ตอบ ผมจึงตอบว่า เอา code ข้างล่างนี้ไป run ดูสิ
for each Item in request.servervariables
response.write Item & " = "
response.write request.servervariables(Item) & "<br>"
next
ถาม ชื่อ field ที่ไม่ควรใช้
ตอบ position, desc เป็นต้น
ถาม แปลงอักษรเป็นวันที่
ตอบ
a = "12"
b = "31"
c = "49"
d = a & "/" & b & "/" & c
e = CDate(d)
response.write(Formatdatetime(e,1))
การเขียนภาษา ASP : แบบเรียงตามบทเรียน
บทเรียนนี้ใช้วิธีแสดงตัวอย่าง Source code ให้ศึกษา และ ท่านสามารถ ทดลองประมวลผล ได้ทันที
การทำให้ Windows เป็น Web server และบริการ ASP
Free Webhosting : 7host.com (ทดสอบกับฐานข้อมูล : ok)
Free Webhosting : globalweb.com
Free Webhosting : 1asphost.com (ทดสอบกับฐานข้อมูล : error /thaiall/database/dthai97.mdb)
Free Webhosting : domaindlx.com (ทดสอบกับฐานข้อมูล : error /thaiall/database/dthai97.mdb)
Free Webhosting : brinkster.com for education (6 Months Login required - กุมภาพันธ์ 49)
Free Webhosting : thai.net (รุ่นใหม่เคยเห็นบริการ ASP ตรวจสอบ ก.พ.49 พบว่าปิดรับสมาชิกใหม่)
Free Webhosting : websamba.com
Free Webhosting : www4.ewebcity.com/thaiall (ปิดบริการ 47)
Free Webhosting : www.frontuk.com/thaiall (ปิดบริการ 47)
Free Webhosting : thaiall.webhostme.com (ปิดบริการ 48)

    Free Webhosting : www.websamba.com/thaiall
  1. เรียน programming ด้วย Pyramid เบื้องต้น (รับ request.querystring)
  2. เรียน programming ด้วย Pyramid ชั้นกลาง (รับ request.querystring ผ่าน method get)
  3. ฟังก์ชันพื้นฐานของ ASP (แสดง syntax ของ function 23 ตัว)
  4. ส่งค่า Option ไปเลือก Table (เป็นชุดคำสั่งง่าย ๆ เพื่อเลือกเรียกตารางมาแสดง)
  5. การสั่งทำซ้ำด้วย for, while (โปรแกรมแรกของท่าน) (พื้นฐานละเอียด)
  6. การเรียกใช้ค่า env และ function (ให้รู้จักตัวแปรเบื้องต้น)
  7. การเขียน ASP ร่วมกับ HTML (แสดงความต่างและเหมือน)
  8. การเขียนตาราง ASCII (ใช้ฟังก์ชัน ASC, CHR)
  9. การอ่าน Access มาพิมพ์ (เริ่มต้นเรียนรู้ MDB)
  10. การเพิ่มข้อมูลAccessแบบADO+SQL (รับค่าจาก form)
  11. การทำระบบสมาชิกใน Access (เพิ่ม ลบ แก้ไขได้)
  12. การทำระบบสมาชิก(Confirm) (ถามย้ำก่อน ประมวลผล)
  13. การเขียน Search Engine อย่างง่าย (มี mdb ให้ download ฟรี)
  14. การสุ่มหลายค่า(ซ้ำและไม่ซ้ำ) (ใช้ randomize)
  15. การส่ง Mail ด้วย ASP (ใช้ smtp เป็นหลัก)
  16. การทำ Counter จาก Text File (สร้าง ปรับปรุง และพิมพ์ จาก text file)
  17. บริหารกระดานข่าวสมัครงาน (อย่างง่าย ๆ ไม่สวยงาม และยังไม่ได้ปรับรายงาน)
  18. ศูนย์สอบ online หลายชุด (รับคำสั่งทั้งจาก url และ form ได้)
  19. การเขียนโปรแกรมรายงานผลการเรียน (ทำเป็นบริการจริง ๆ ให้ครู และนักเรียนเข้าใช้บริการ)
    หรือ จะเรียกผ่านบริการ redirection ได้เป็น http://go.to/grade ลองไปใช้บริการดูนะครับ ไม่ใช่ครู ก็ทดสอบได้
    ข้อแนะนำเบื้องต้น
    1. แฟ้ม mdb ของ MS Access 97 ที่ 1asphost.com หรือ domaindlx.com ต้องกำหนดตำแหน่งแฟ้มใหม่ดังตัวอย่าง (refer)
        conn = "driver={microsoft access driver (*.mdb)}; dbq="
        conn = conn & server.mappath("/USERNAME/database/dthai97.mdb")
    2. แฟ้ม mdb ของ MS Access 97 ที่ webhostme.com ต้องเก็บใน /cgi-bin จึงจะปรับปรุงได้ มิเช่นนั้นจะอ่านได้อย่างเดียว
    3. แฟ้ม mdb ของ MS Access 97 ที่ websamba.com เก็บห้องไหนก็ได้ไม่มีปัญหา
    4. แฟ้ม mdb ของ MS Access 97 ที่ ewebcity.com ต้องเก็บใน /db จึงจะเรียกใช้ได้ (แต่ปัจจุบันปิดบริการไปแล้ว)
FAQs : Frequently Asked Questions
       ถ้ามีปัญหา ก่อนจะถามผม ช่วยลองเขียนโปรแกรมง่าย ๆ ดูก่อน ท่านอาจเจอปัญหา และวิธีแก้ปัญหาด้วยตนเอง เช่น อ่านข้อมูลจาก mdb มาแสดง แต่ถ้าไม่ได้ให้ copy mdb ที่ผมเปิดให้ copy พร้อม source ไปลองดู กับ server ฟรีนั้นก่อนนะครับ .. หลายปัญหาเป็นเส้นผมบังภูเขา ขยับนิดนึ่งก็เรียบร้อย
  1. ทำไมฟ้อง database may be corrupt :
    เพราะ compiler ของฝรั่งเป็นฝรั่ง แต่ของไทยเป็นไทย เมื่อสร้าง mdb แล้วปรับปรุงแก้ไขอะไรมาก ๆ ทำให้โครงสร้างภายในเปลี่ยน เช่น การ compact database อาจทำให้ใช้งานในเว็บฝรั่งไม่ได้ วิธีแก้ให้เริ่มจาก copy mdb ของผมไปทดลองดู โดยเปลี่ยนโครงสร้าง ถ้าใช้ได้แล้วค่อยทดลองสร้างของตนเอง แต่อย่าพยายามปรับโครงสร้าง ไม่งั้นก็ไม่ work ตัวอย่างแฟ้ม mdb ที่ให้ลอง Download ไปใช้คือ search.mdb(276KB) ใช้ในบทเรียนเรื่อง การเขียน Search Engine อย่างง่าย หรือแฟ้ม quiz.mdb(84KB) ใช้ในบทเรียนเรื่อง ศูนย์สอบ Online หลายชุด
  2. ทำไมติดต่อ database ไม่ได้ บอกว่า sql error :
    เพราะ แต่ละ server กำหนดให้เราติดต่อกับ mdb แตกต่างกัน บางครั้งใช้แบบนั้นติดต่อได้ พอเปลี่ยนเครื่องทดสอบก็มีปัญหา วิธีแก้ให้เปิดเว็บของเขาว่า ให้เขียนโปรแกรมติดต่อกับ server ของเขาอย่างไร เมื่อ มกราคม 49 ผมก็ทดสอบกับ 1asphost.com ก็ไม่ได้ จึงต้องหันไปทดสอบกับ 7host.com ปรากฎว่าไม่พบปัญหาครับ
  3. สามารถ Download Jet40Repl.exe สำหรับ update Microsoft Jet Database รุ่น 4.0 เพราะมีข่าวว่ามีปัญหาเรื่องจุดบกพร่อง แต่ถ้าต้องการทราบว่า เครื่องของเรามี Microsoft Jet Database รุ่นใด สามารถตรวจสอบด้วยการเปิด regedit แล้วหาคำว่า "Microsoft Jet" และกด F3 เพื่อ Find next ก็จะแสดงเลขรุ่นมาให้เห็น
    global.asa
    ถ้าเก็บแฟ้ม global.asa ในห้องที่เก็บแฟ้ม .asp ผล คือ เมื่อเปิดแฟ้มที่สกุล .asp ใดก็ตาม IIS จะช่วย แทรกภาพมุมบนซ้าย ในเว็บเพจนั้น
    สามารถนำไปใช้เพิ่ม counter ให้ทุกหน้าโดยอัตโนมัติ
    <script language=vbscript runat=server>
    sub Session_OnStart
      response.write "<div style='position:absolute; left:0px; top:0px;z-index:0;'>"
      response.write "<img src=http://www.thaiall.com/me/picme.jpg></div>"
      Session.Abandon
    end sub
    </script>
    

Addandlist.asp [ Test at 7host.com : ok ]
    Download : dthai97.mdb 70 KB
    
    โปรแกรมเพิ่มข้อมูล และแสดงผลอย่างง่าย ๆ ใน Microsoft Access ด้วยภาษา ASP
    <body><font size=0> <form action=addandlist.asp method=post> fid: <input name=fid> fname: <input name=fname> fsalary: <input name=fsalary> <input type=submit> </form> <a href=addandlist.asp>list</a><hr> <% if (request.form("fid") > 0) then set conn = server.createobject("ADODB.Connection") conn.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("dthai97.mdb") sql = "insert into tbthai ( fid, fname, fsalary ) SELECT " sql = sql & " " & request.form("fid") & " as fid, " sql = sql & " '" & request.form("fname") & "' as fname, " sql = sql & " " & request.form("fsalary") & " as fsalary; " set rs = conn.Execute(sql) conn.close set conn = nothing else set conn = server.createobject("adodb.connection") conn.open "provider=microsoft.jet.oledb.4.0; data source=" & server.mappath("dthai97.mdb") response.write(server.mappath("dthai97.mdb") & "<br>") sql = "select * from tbthai" set rs = conn.execute(sql) do while not rs.eof response.write(rs("fid")&rs("fname")&rs("fsalary")&"<br>") rs.MoveNext loop conn.close set rs = nothing set conn = nothing end if %> </body>
Download : dthai97.mdb 70 KB
ตัวอย่าง dlist1.asp : 

การเชื่อมต่อฐานข้อมูลแบบ DSNLess ด้วย Microsoft access (ตัวอย่างนี้ใช้ recordset)
    <% set rs = server.createobject("adodb.recordset") ' conn = "driver={microsoft access driver (*.mdb)}; dbq=d:\thaiall.com\asp\dthai97.mdb;" conn = "driver={microsoft access driver (*.mdb)}; dbq=" & server.mappath("dthai97.mdb") sql = "select * from tbthai" rs.open sql, conn, 1, 3 response.write("Total record : "& rs.recordcount & "<br>") do while not rs.eof response.write(rs("fid") & " " & rs("fname") & " " & rs("fsalary") & "<br>") rs.MoveNext loop rs.close set rs = nothing ' rs.pagesize = 5 ' totalpage = rs.pagecount ' pg = 1 ' rs.absolutepage = pg %>

ตัวอย่าง dlist2.asp : 

การเชื่อมต่อฐานข้อมูลแบบ DSNLess ด้วย Microsoft access (ใช้ execute SQL)
    <% set conn = server.createobject("adodb.connection") conn = "driver={microsoft access driver (*.mdb)}; dbq=" & server.mappath("dthai97.mdb") sql = "select * from tbthai" set rs = conn.execute(sql) do while not rs.eof response.write(rs("fid") & " ") response.write(rs("fname") & " ") response.write(rs("fsalary") & "<br>") rs.MoveNext loop conn.close set rs = nothing set conn = nothing %>

ตัวอย่าง dlist3.asp : 

การเชื่อมต่อฐานข้อมูลแบบ OLEDB Provider ด้วย Microsoft jet (ใช้ได้ทั้ง MS Access และ MS Excel)
    <% set conn = server.createobject("adodb.connection") ' conn.open "provider=microsoft.jet.oledb.4.0; data source=c:\thai.xls; extended properties=""excel 8.0; hdr=yes"";" ' conn.open "driver={mysql}; server=localhost; database=dthai; uid=; pwd=;" ' conn.open "driver={sql server}; server=localhost; database=dthai; uid=sa; pwd=;" ' conn.open "driver={microsoft odbc for oracle}; server=oracleserver; uid=; pwd=;" ' conn.open "driver={microsoft access driver (*.mdb)}; dbq=" & server.mappath("dthai97.mdb") ' conn.open "driver={microsoft access driver (*.mdb)}; dbq=d:\thaiall.com\asp\dthai97.mdb;" conn.open "provider=microsoft.jet.oledb.4.0; data source=" & server.mappath("dthai97.mdb") ' conn.execute("delete * from tbthai") บรรทัดนี้เพิ่มได้ แต่ผลคือไม่แสดงอะไรนะครับ sql = "select * from tbthai" set rs = conn.execute(sql) do while not rs.eof response.write(rs("fid") & " " & rs("fname") & " " & rs("fsalary") & "<br>") rs.MoveNext loop conn.close set rs = nothing set conn = nothing %>

ตัวอย่าง dlist4.asp : 

การเชื่อมต่อฐานข้อมูลแบบ DSN (Data Source Name) ที่ไม่ใช้ recordset
    <% ' xdthai97 คือ Data Source Name ที่ถูกสร้างด้วย ODBC Data source ใน control panel ' ให้เลือก User DSN, Add, Microsoft Access Drriver.. , Finish ' แล้วพิมพ์ xdthai97 ในช่อง Data Source Name แล้วอย่าพึ่งกดปุ่ม OK ' ให้กดปุ่ม Select เพื่อเลือกแฟ้มชื่อ dthai97.mdb ที่อยู่ในคอมพิวเตอร์ แล้วกดปุ่ม OK ' ผลการเพิ่ม จะพบ xdthai97 อยู่ในส่วนของ User DSN ซึ่งจะชี้ไป dthai97.mdb อัตโนมัติ ' conn.open "dsn=xdthai97;uid;pwd;" ก็ใช้ได้ set conn = server.createobject("adodb.connection") conn.open "xdthai97", "", "" sql = "select * from tbthai" set rs = conn.execute(sql) do while not rs.eof response.write(rs("fid") & " " & rs("fname") & " " & rs("fsalary") & "<br>") rs.MoveNext loop conn.close set rs = nothing set conn = nothing %>

ตัวอย่าง dlist5.asp : 

การเชื่อมต่อฐานข้อมูลแบบ DSN (Data Source Name) ที่ใช้ recordset
ทดสอบ DSN ที่เชื่อมต่อกับ MYSQL ในเครื่องที่ลง MYODBC แล้วก็ ok มีตัวอย่างที่ http://www.thaiall.com/mysql เช่นกัน
    <% set conn = server.createobject("adodb.connection") conn.open "xdthai97", "", "" set rs = server.createobject("adodb.recordset") sql = "select * from tbthai" rs.open sql, conn, 1, 3 do while not rs.eof response.write(rs("fid") & " " & rs("fname") & " " & rs("fsalary") & "<br>") rs.MoveNext loop conn.close set rs = nothing set conn = nothing %>

ตัวอย่าง dlist6.asp : 

การเชื่อมต่อฐานข้อมูล MYSQL ในเครื่องที่ลง MYODBC มีตัวอย่างที่ http://www.thaiall.com/mysql
ถ้าเครื่องที่เชื่อมต่อชื่อ localhost ฐานข้อมูลชื่อ test ส่วน user และ password คือ u และ p <% ConnString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=test;uid=u;password=p;" Set conn = Server.CreateObject("ADODB.Connection") conn.Open ConnString Set rs = conn.Execute("SELECT * FROM cust") do while not rs.eof response.write(rs("cust") & " " & rs("custname") & "<br>") rs.MoveNext loop conn.close set rs = nothing set conn = nothing %>
ตัวอย่างการเชื่อมต่ออื่น ๆ

Other Connection String : http://www.carlprothman.net/Default.aspx?tabid=81
    การเชื่อมต่อฐานข้อมูลแบบ OLEDB Provider ด้วย Active Directory service
    conn.open "PROVIDER=ADSDSObject;USER ID=Admin;PASSWORD=;"
    การเชื่อมต่อฐานข้อมูลแบบ OLEDB Provider ด้วย Microsoft SQL server (ธรรมดา)
    conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=SQL Server;" &_ "INITIAL CATALOG=Member;USER ID=sa;PASSWORD=;"
    การเชื่อมต่อฐานข้อมูลแบบ OLEDB Provider ด้วย Microsoft SQL server (IP address)
    conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=202.29.0.1, 1433;" &_ "NETWORK LIBRARY=DBMSSOCN;INITIAL CATALOG=Member;USER ID=sa;PASSWORD=;"
    การเชื่อมต่อฐานข้อมูลแบบ OLEDB Provider ด้วย Microsoft excel
    conn.open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=c:\member.xls;"&_ "extended properties=""Excel 8.0; HDR=Yes"";"

การอ่านข้อมูลจาก .xls ด้วย ASP :: ตัวอย่างนี้กำหนด ชื่อ พื้นที่ ที่จะ select ข้อมูลมาใช้ :: Right click to download [ dthai97.xls 13 KB ]
    <% filexls = "dthai97.xls" tbname = "dthai1" f1 = "eid" f2 = "ename" ' =============================================== ' 2 method : ok ' dv = "driver={microsoft excel driver (*.xls)}; dbq=" & server.mappath(filexls) ' dv = dv & "; extended properties='excel 8.0; hdr=yes';" dv = "provider=microsoft.jet.oledb.4.0; data source=" & server.mappath(filexls) dv = dv & "; extended properties='excel 8.0; hdr=yes';" set conn = server.createobject("adodb.connection") conn.open dv sql = "select * from " & tbname set rs = conn.execute(sql) do while not rs.eof response.write(rs(f1) & " " & rs(f2) & "<br>") rs.MoveNext loop conn.close set rs = nothing set conn = nothing %>

การติดต่อกับ crystal report :: คุณ unesco@thaimail.com ถามผม และส่ง code มาให้ ช่วงนี้ยังไม่ได้ศึกษา แต่ copy ไว้ก่อน :: ตัวอย่างข้างล่างนี้ยังไม่ ok คำถามคือจะเอาข้อมูลเขียนลง crystal report ยังไง ซึ่งผมก็ตอบไม่ได้
    Dim Cn,Rs,Rp,App Set Conn=Server.Createobject("ADODB.Connection") conn.open ("myoffice") set rs = server.createobject("adodb.recordset") rs.activeconnection=conn rs.open "select rid, rname from resource" Set App = Server.CreateObject("CrystalRuntime.Application") set rp = app.openreport("c:\inetpub\wwwroot\resource.rpt") rp.sections(1).suppress = true rp.sections(2).height=2000 set fd=rp.sections(2).addtextobject("ใบเสนอราคา",3000,1000) fd.width = 5000 : fd.height=500 fd.font.name="AngsanaUPC" fd.font.size=18
Short Sample :
    
    <%
    ' หาชื่อ Folder ที่ run โปรแกรมนี้
    ' from http://www.codefixer.com/tutorials/array_functions.asp
    dim a,n
    a = Split(request.servervariables("PATH_TRANSLATED"),"\")
    n = a(0)
    for i=1 to ubound(a) - 1
      n = n & "\" & a(i)
    next
    response.write n
    %>
    
คำสั่งน่ารู้ :
  1. m = replace(request.querystring("messages"),chr(39),"'")
    เพื่อแก้ปัญหาส่งข้อมูลไม่เข้า หากรับเครื่องหมาย ' เข้าไปใน text หรือ textarea จะทำให้ error
  2. session("a") = request.form("a")
    เก็บค่าจาก form ที่ใช้ method post เข้า session
  3. session("a") = request.querystring("a")
    เก็บค่าจาก form ที่ใช้ method get เข้า session
  4. response.write(session("a"))
    นำค่าจาก session ที่เก็บไว้มาใช้
  5. response.end
    นั่งคิดอยู่ตั้งนานว่าจะหยุดการทำงานได้อย่างไร จะใช้ exit อะไรดี ก็ได้ อ.ถนอม เฉลยครับ
  6. response.redirect("http://www.thaiall.com")
    ย้ายจากเว็บเพจเดิม ไปหน้าใหม่ทันที คล้ายคำสั่ง header("Location: http://www.thaiall.com"); ในภาษา PHP
  7. <!--#include file="wisdom.inc"-->
    <!--#include file="wisdom.asp"-->

    เรียก External File มาใช้ คล้าย require ใน php และใช้ได้ทั้งสกุล inc และ asp
  8. response.write(date() & now() & time() & month(date()) & day(date()) & year(date()))
    response.write(hour(now()) & minute(now()) & second(now()) & weekday(now()))
    response.write(formatdatetime(now(),vbgeneraldate) & formatdatetime(now(),vblongtime))

    แสดงเวลาแบบต่าง ๆ เช่น 28/9/2549 14:55:11
  9. username1 = 0
    if isnumeric(request.form("username1")) then username1 = request.form("username1")

    ตรวจสอบการเป็นตัวเลข ถ้าส่งตัวอักษรเข้า SQL จะมีปัญหา จึงต้องแปลงก่อน
  10. dim filename, fs, f
    filename = "c:\wwww\gallery\" & request.querystring("id") & ".jpg"
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    if fs.FileExists(filename) then
    set f=fs.GetFile(filename)
    f.Delete
    end if

    ลบแฟ้มในห้องที่กำหนดจาก GET เช่น x.asp?id=5

http://www.perlphpasp.com
2101. intro/default.asp
2102. intro/function.asp
2103. intro/p01.asp
2104. intro/p02.asp
2105. intro/p03.asp
2106. intro/p04.asp
2107. intro/randomeasy.asp
2108. intro/randomarray.asp
2109. intro/numtochar.asp
2201. sort/default.asp
2202. sort/bubble.asp
2203. sort/newbubble.asp
2204. sort/insertion.asp
2205. sort/selection.asp
2206. sort/shell.asp
2301. keepvar/default.asp
2302. keepvar/addapplication.asp
2303. keepvar/addsession.asp
2304. keepvar/removeappl.asp
2305. keepvar/addsubj.asp
2401. textsearch/search.dat
2402. textsearch/default.asp
2403. textsearch/crtsearch.asp
2404. textsearch/listsearch.asp
2405. textsearch/find.asp
2406. textsearch/delrec.asp
2407. textsearch/restore.asp
2502. updatemdb/default.asp
2503. updatemdb/crttab.asp
2504. updatemdb/selecttab.asp
2505. updatemdb/inserttmpch.asp
2506. updatemdb/insert6.asp
2507. updatemdb/searchtmpch.asp
2508. updatemdb/edittmpnum.asp
2509. updatemdb/controlrec.asp
2510. updatemdb/deltmpch.asp
2511. updatemdb/droptab.asp
2602. quiz/default.htm
2603. quiz/displayq.asp
2604. quiz/displayqz.asp
2605. quiz/quizauto.asp
2606. quiz/quizjv.asp
2701. emailconfirm/default.asp
2702. emailconfirm/checkpass.asp
2703. emailconfirm/sendmail.asp
2801. creditcard/default.asp
2802. creditcard/ccard.inc
2902. casereg/default.htm
2903. casereg/listpage.asp
2904. casereg/groupadv.asp
2905. casereg/regist.asp 
From : http://www.csidata.com/custserv/onlinehelp/VBSdocs/vbsalp2.htm
Alphabetic Keyword List
Abs Add Method AddFolders Method Addition Operator (+) And Operator Array Asc Assignment Operator (=) AtEndOfLine Property AtEndOfStream Property Atn Attributes Property AvailableSpace Property BuildPath Method Call Statement CBool CByte CCur CDate CDbl Chr CInt Clear Method CLng Close Method Column Property CompareMode Property Concatenation Operator (&) Const Statement Copy Method CopyFile Method CopyFolder Method Cos Count Property CreateFolder Method CreateObject CreateTextFile Method CSng CStr Date DateAddFunction DateCreated Property DateDiff DateLastAccessed Property DateLastModified Property DatePart DateSerial DateValue Day Delete Method DeleteFile Method DeleteFolder Method Description Property Dictionary Object Dim Statement Division Operator (/) Do...Loop Statement Drive Object Drive Property DriveExists Method DriveLetter Property Drives Collection Drives Property DriveType Property Empty Eqv Operator Erase Statement Err Object Exists Method Exit Statement Exp Exponentiation Operator (^) False FileExists Method File Object Files Collection Files Property FileSystemObject Object FileSystem Property Filter Fix Folder Object Folders Collection FolderExists Method For...Next Statement For Each...Next Statement FormatCurrency FormatDateTime FormatNumber FormatPercent FreeSpace Property Function Statement GetAbsolutePathName Method GetBaseName Method GetDrive Method GetDriveName Method GetExtensionName Method GetFile Method GetFileName Method GetFolder Method GetObject GetParentFolderName Method GetSpecialFolder Method GetTempName Method Hex HelpContext Property HelpFile Property Hour If...Then...Else Statement Imp Operator InputBox InStr InStrRev Int Integer Division Operator (\) Is Operator IsArray IsDate IsEmpty IsNull IsNumeric IsObject IsReady Property IsRootFolder Property Item Property Items Method Join Key Property Keys Method LBound LCase Left Len Line Property LoadPicture Log LTrim Mid Minute Mod Operator Month MonthName Move Method MoveFile Method MoveFolder Method MsgBox Muliplication Operator (*) Name Property Negation Operator (-) Not Operator Now Nothing Null Number Property Oct On Error Statement OpenAsTextStream Method OpenTextFile Method Operator Precedence Option Explicit Statement Or Operator ParentFolder Property Path Property Private Statement Public Statement Raise Method Randomize Statement Read Method ReadAll Method ReadLine Method ReDim Statement Rem Statement Remove Method RemoveAll Method Replace RGB Right Rnd RootFolder Property Round RTrim ScriptEngine ScriptEngineBuildVersion ScriptEngineMajorVersion ScriptEngineMinorVersion Second Select Case Statement SerialNumber Property Set Statement Sgn ShareName Property ShortName Property ShortPath Property Sin Size Property Skip Method SkipLine Method Source Property Space Split Sqr StrComp String StrReverse Sub Statement SubFolders Property Subtraction Operator (-) Tan Time TextStream Object TimeSerial TimeValue TotalSize Property Trim True Type Property TypeName UBound UCase VarType VolumeName Property Weekday WeekdayName While...Wend Statement Write Method WriteBlankLines Method WriteLine Method Xor Operator Year

แนะนำเว็บใหม่ : แสดงผลการจัดอันดับ
รักลำปาง : lampang.thcity.com : topsiam.com : cookkoo.com : โยนก
ศูนย์สอบ : รวมบทความ : Download : yourname@thaiall.com
ติดต่อ ทีมงาน ชาวลำปาง มีฝันเพื่อการศึกษา Tel.0-1992-7223