¡¡¾³£Ê¹Óõ½ÓйØÊý¾Ý¿âµÄ²Ù×÷¡£°üÀ¨Á¬½Ó´úÂë¡¢SQLÃüÁîµÈµÈ£¬ÓÖ²»Ôø¿ÌÒâÈ¥¼ÇÒäËüÃÇ£¨ÎÒ±¾ÈËÊDz»Ô¸ÒâÈ¥¼ÇÕⶫ¶«£©£¬ËùÒÔ³£³£ÔÚÓõ½µÄʱºòÓÖÈ¥²éÊé±¾£¬·À´·È¥¡£Ò»Ð©±È½ÏÉÙÓõÄÊý¾Ý¿â»¹²»Ò»¶¨ÄÜ˳ÀûÕÒµ½£¬ËùÒÔÏÖÔÚ°ÑËüÃÇÈ«¹éÄɵ½ÕâÀÌṩ´ó¼Ò²Î¿¼¡£
<Ò»>Êý¾Ý¿âµÄÁ¬½Ó·½·¨£º
¡¡¡¡1.AccessÊý¾Ý¿âµÄDSN-lessÁ¬½Ó·½·¨:
set adocon=Server.Createobject("adodb.connection") adoconn.Open"Driver={Microsoft Access Driver(*.mdb)};DBQ="& _ Server.MapPath("Êý¾Ý¿âËùÔÚ·¾¶")
¡¡¡¡2.Access OLE DBÁ¬½Ó·½·¨£º set adocon=Server.Createobject("adodb.connection") adocon.open"Provider=Microsoft.Jet.OLEDB.4.0;"& _ "Data Source=" & Server.MapPath("Êý¾Ý¿âËùÔÚ·¾¶")
¡¡¡¡3.SQL serverÁ¬½Ó·½·¨£º set adocon=server.createobject("adodb.recordset") adocon.Open"Driver={SQL Server};Server=(Local);UID=***;PWD=***;"& _ "database=Êý¾Ý¿âÃû;"
¡¡¡¡4.SQL server OLE DBÁ¬½Ó·½·¨: set adocon=Server.Createobject("adodb.connection") adocon.open"provider=SQLOLEDB.1;Data Source=RITANT4;"& _ "user ID=***;Password=***;"& _ "inital Catalog=Êý¾Ý¿âÃû"
¡¡¡¡5.Oracle Á¬½Ó·½·¨: set adocon=Server.Createobject("adodb.connection") adocon.open"Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;pwd=pass;"
¡¡¡¡6.Oracle OLE DB Á¬½Ó·½·¨: set adocon=Server.Createobject("adodb.connection") adocon.open"Provider=OraOLEDB.Oracle;data source=dbname;user id=admin;password=pass;"
¡¡¡¡7.dBase Á¬½Ó·½·¨: set adocon=Server.Createobject("adodb.connection") adocon.open"Driver={microsoft dbase driver(*.dbf)};driverid=277;dbq=------------;"
¡¡¡¡8.mySQL Á¬½Ó·½·¨: set adocon=Server.Createobject("adodb.connection") adocon.open"Driver={mysql};database=yourdatabase; uid=username;pwd=yourpassword;option=16386;"
¡¡¡¡9.Visual Foxpro Á¬½Ó·½·¨: set adocon=Server.Createobject("adodb.connection") adocon.open"Driver={microsoft Visual Foxpro driver};sourcetype=DBC;sourceDB=*.dbc;Exclusive=No;"
¡¡¡¡10.MS text Á¬½Ó·½·¨: set adocon=Server.Createobject("adodb.connection") adocon.open"Driver={microsoft text driver(*.txt; *.csv)};dbq=-----;"&_ "extensions=asc,csv,tab,txt;Persist SecurityInfo=false;"
¡¡¡¡11.MS text OLE DB Á¬½Ó·½·¨: set adocon=Server.Createobject("adodb.connection") adocon.open"Provider=microsof.jet.oledb.4.0;data source=your_path;"&_ "Extended Properties'text;FMT=Delimited'"
<¶þ>³£ÓõÄËÄÖÖSQLÃüÁ
¡¡¡¡1.²éѯÊý¾Ý¼Ç¼(Select) ¡¡¡¡Óï·¨£ºSelect ×ֶδ®ÐÐ From table Where ×Ö¶Î=ÄÚÈÝ ¡¡¡¡Àý×Ó£ºÏë´Óbook±íÖÐÕÒ³ö×÷ÕßΪ"cancer"µÄËùÓмǼ£¬SQLÓï¾ä±ãÈçÏ£º select * from book where author=¡¯cancer¡¯
¡¡¡¡"*"ÊÇÈ¡³öbook±íËùÓеÄ×ֶΣ¬Èç²éѯµÄ×Ö¶ÎֵΪÊý×Ö£¬ÔòÆäºóµÄ"ÄÚÈÝ"±ãÎÞÐë¼ÓÉϵ¥ÒýºÅ£¬ÈçÊÇÈÕÆÚ£¬ÔòÔÚAccessÖÐÓÃ(#)°üÀ¨£¬¶øÔÚSQL serverÖÐÔòÓÃ(¡¯)°üÀ¨£¬ Èç: select * from book where id=1 select * from book where pub_date=#2002-1-7# (Access) select * from book where pub_date=¡¯2002-1-7¡¯ (SQL Server)
¡¡¡¡Ìáʾ£º ¡¡¡¡ÈÕÆÚº¯Êýto_date²»ÊDZê×¼sqlÎÄ£¬²»ÊÇËùÓеÄÊý¾Ý¿âÊÊÓã¬ËùÒÔ´ó¼ÒÔÚʹÓõÄʱºòÒª²Î¿¼Êý¾Ý¿â¾ßÌåÓï·¨
¡¡¡¡ÁíÍâÈç¹ûÊDzéѯ´«ÈëµÄ±äÁ¿£¬ÔòÈçÏ£º strau=request.form("author") strsql="select * from book where author=¡¯"&strau&"¡¯"
¡¡¡¡Èç¹û²éѯµÄÊÇÊý×Ö£¬Ôò£º intID=request.form("id") strsql="select * from book where id="&intID
¡¡¡¡ÔںܶàÊý¾Ý¿âÖУ¬È磺oracle£¬ÉÏÃæµÄÓï¾äÊÇ¿ÉÒÔд³É£º strsql="select * from book where id='"&intID&"'"
¡¡¡¡µ«ÊÇ×Ö·ûÐÍÒ»¶¨²»ÄÜ°´ÕÕÊý×Ö¸ñʽд£¬ÐèҪעÒâ¡£
¡¡¡¡2.Ìí¼Ó¼Ç¼(Insert) ¡¡¡¡Óï·¨£º Insert into table(field1,field2,....) Values (value1,value2,....)
¡¡¡¡Àý×Ó£ºÌí¼ÓÒ»×÷ÕßÊÇ"cancer"µÄ¼Ç¼Èëbook±í: insert into book (bookno,author,bookname) values (¡¯CF001¡¯,¡¯cancer¡¯,¡¯CancerÎÞ×é¼þÉÏ´«³ÌÐò¡¯)
¡¡¡¡Í¬Ñù£¬Èç¹ûÓõ½±äÁ¿¾ÍÈçÏ£º strno=request.form("bookno") strau=request.form("author") strname=request.form("bookname") strsql="insert into book (bookno,author,bookname) values (¡¯"&strno&"¡¯,¡¯"&strau&"¡¯,¡¯"&strname&"¡¯)"
¡¡¡¡3.ÓÃRecordset¶ÔÏóµÄAddnew²åÈëÊý¾ÝµÄ·½·¨: ¡¡¡¡Óï·¨£º rs.addnew rs("field1").value=value1 rs("field2").value=value2 ... rs.update
¡¡¡¡4.ÐÞ¸ÄÊý¾Ý¼Ç¼(Update) ¡¡¡¡Óï·¨£º update table set field1=value1,field2=value2,...where fieldx=valuex
¡¡¡¡Àý×Ó£º update book set author=¡¯babycrazy¡¯ where bookno=¡¯CF001¡¯
¡¡¡¡Èç¹ûÓõ½±äÁ¿¾ÍÈçÏ£º strno=request.form("bookno") strau=request.form("author") strsql="update book set author=¡¯"&strau&"¡¯ where bookno=¡¯"&strno"¡¯"
¡¡¡¡5.Recordset¶ÔÏóµÄUpdate·½·¨: ¡¡¡¡Óï·¨£º rs("field1").value=value1 rs("field2").value=value2 ... rs.update
¡¡¡¡×¢Ò⣺ʹÓÃÓï·¨3ºÍÓï·¨5µÄʱºò£¬Ò»¶¨Òª×¢Òâ×ֶεÄÀàÐÍ£¨ÓÈÆäÊÇÈÕÆÚÐÍ£©Ò»Ö£¬·ñÔò³ö´íµÄ¼¸Âʷdz£µÄ¸ß¡£
¡¡¡¡Àý×Ó£º strno=request.form("bookno") strau=request.form("author") set adocon=server.createobject("adodb.connection") adocon.open "Driver={Microsoft Access Driver(*.mdb)};DBQ=" & _ Server.Mappath=("/cancer/cancer.mdb") strsql="select * from book where bookno=¡¯"&strno&"¡¯" set rs=server.createobject("adodb.recordset") rs.open strsql,adconn,1,3 if not rs.eof then ¡¯Èç¹ûÓд˼ǼµÄ»° rs("author").value=strau rs.update end if rs.close set rs=nothing adocon.close set adocon=nothing
¡¡¡¡6.ɾ³ýÒ»Ìõ¼Ç¼(Delete) ¡¡¡¡Óï·¨£º Delete table where field=value
¡¡¡¡Àý×Ó£ºÉ¾³ýbook±íÖÐ×÷ÕßÊÇcancerµÄ¼Ç¼ delete book where author=¡¯cancer¡¯
¡¡¡¡(×¢Ò⣺Èç¹ûbook±íÖÐauthor×ֶεÄֵΪcancerµÄ¼Ç¼ÓжàÌõ£¬½«»áɾ³ýËùÓÐauthorΪcancerµÄ¼Ç¼)
¡¡¡¡ºÃÁË£¬Ñ§»áÁËÓÃÕâЩ²Ù×÷£¬´ó¼ÒÔÚÓÃasp²Ù×÷Êý¾Ý¿âµÄʱºò£¬¸ÃÊÇûÓÐʲôÎÊÌâÁË¡£
|