18-4 使用 SQL 來新增、修?、刪????

bW@`Aڭ̤wgФFpϥ SQL ˵ơAo@`Npϥ SQL OӹƮwisWBקBRƵʧ@C bUCdҤAڭ̦b ASP ϥ SQL ӹƮwiUCBzG
  1. إߤ@Ӹƪ friendC
  2. JⵧơC
  3. R@ơC
  4. s@ơC
  5. Rƪ friendC
dҦpUG

Example]database/dbAllQuery01.asp^G

lXpUG

lɡ]database/dbAllQuery01.asp^G]ǦϰUYi^
<%@ language="jscript" %>
<% title="ϥ SQL ƮwisWBקBR" %>
<!--#include file="../head.inc"-->
<hr>

<!--#include file="../listQueryResult.inc"-->
<%
// إ߸Ʈws
database="test.mdb";
myConn = Server.CreateObject("ADODB.Connection");
myConn.ConnectionString = "DBQ=" + Server.MapPath(database) + ";Driver={Microsoft Access Driver (*.mdb)};Driverld=25;FIL=MS Access;";

// إ߸ƪ friend
Response.Write("إ߸ƪ friend ...<br>");
myConn.Open();
sql = "CREATE TABLE friend (FirstName char(50), LastName char(50), Company char(100), City char(50), BirthDate date)"; 
myConn.Execute(sql);
// JĤ@
sql = "INSERT INTO friend (FirstName, LastName, City, Company) VALUES ('Roger', 'Jang', 'Taipei', 'xWj')";
myConn.Execute(sql);
// JĤG
sql = "INSERT INTO friend (FirstName, LastName, City, Company) VALUES ('Bill', 'Hsu', 'Taipei', '׬')";
myConn.Execute(sql);
myConn.Close();
Response.Write("[JⵧƫAƪ friend eG<br>");
listQueryResult(database, "select * from friend");	// LXƪ

// R@
myConn.Open();
sql = "DELETE FROM friend where LastName='Jang'";
myConn.Execute(sql);
myConn.Close();
Response.Write("R@ƫAƪ friend eG<br>");
listQueryResult(database, "select * from friend");	// LXƪ

// s@
myConn.Open();
sql = "UPDATE friend SET BirthDate = #3/31/62# WHERE LastName='Hsu'";
myConn.Execute(sql);
myConn.Close();
Response.Write("s@ƫAƪ friend eG<br>");
listQueryResult(database, "select * from friend");	// LXƪ

// Rƪ friend
Response.Write("Rƪ friend ...<br>");
myConn.Open();
sql = "DROP TABLE friend";
myConn.Execute(sql);
myConn.Close();
%>

<hr>
<!--#include file="../foot.inc"-->

bWzdҤApGܪȬO nullANڭ̷bsWƮɡAèS]wȡAӦbƮw]]ww]ȡAҥH~|^ nullC

Dz SQL ̧֪kANOݬݴXӲ{ҤlCUoӽdҡAiHAbWզUجd߰ʧ@AҦpsWBקBRAиլݬݡG

Example]database/modifyDb01.asp^G

ϥ Access Ʈwt@ӦnBOAѤF@ӹϧΤƪdߤApiHϥγoӬdߤͪndߵGAANdߤkন SQL ykAɧANiHN SQL ykKp ASP {XAk󲣥ͽ SQL ykD`nΡAԲӻШe@AṲ̄@աC

ϥ ASP XƮwɡAiѦҤUCpZG

t~nSO`NOGb Access SQL OɡAӳ̭nUΦrG

Ynb ASP {Xϥ SQL UΦrANu?vאּu_vAu*vאּu%vAHŦX@ SQL yзdzWdC]b SQL Server SQL OɡANOΡu_vӤ@ӦrAu%vӤhӦrC^
JScript {]pPΡGΩAݪ ASP