ect("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;pass
word=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 不是标准 sql 文,不是所有的数据库适用,所以大家在使用的时候要 参考数据库具体语法
另外如果是查询传入的变量,则如下:
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") str
sql="insert into book (bookno,author,bookname) values (’"&;strno&;"’,’"&;strau&;"’,’"&;strname&;"’)"
3.