asp与sql server 数据库的连接
<%
'连接数据库————————————————————————————
set conn=server.createobject("adodb.connection")
Connstr="Provider=SQLOLEDB;Data Source=127.0.0.1;UID=sa;PWD=sa;DataBase=web"
'打开数据库——————————————————————————————————
conn.open connstr
'写数据查询语句————————————————————————
set rs=conn.execute("select * from asp where id>2")
'输出查询结果——————————————————————————
do until rs.eof
response.write rs("id")&"<br>"
response.write rs("name")&"<br>"
rs.movenext
loop
%>
************************************
asp与access 数据库的连接
********************************
<% dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("login.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.clear
else
conn.open connstr
if err then
err.clear
end if
end if
set rs=conn.execute("select * from login_info where id>1")
do until rs.eof
response.write rs("id")&"<br>"
response.write rs("username")&"<br>"
response.write rs("password")&"<br>"
rs.Movenext
loop %>
*****************************************************
*****************************************************
<!--#include file="conn.asp"-->
<%
set rs=conn.execute("select * from login_info where id>2")
'set rs=server.createobject("adodb.recordset")
'sql="select * from login_info where id > ='1' "
'rs.open sql,conn,1,1
do until rs.eof
response.write rs("id")&"<br>"
response.write rs("username")&"<br>"
response.write rs("password")&"<br>"
rs.Movenext
loop
%>
**********************************************************
***********************************************************
连结其他数据库的方法(*.dbf,*.txt,excel,foxpro等) ----收藏
2002-10-30 18:41:05 浏览次数:145
'连结dbf文件
<%
' 建立Connection 对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Visual FoxPro Driver};"
SourceType = "SourceType=DBF;"
DBPath = "SourceDB=" & Server.MapPath( "Dbf" )
' 调用Open 方法连接数据库
conn.Open Driver & SourceType & DBPath
Set rs = Server.CreateObject("ADODB.Recordset")
' 打开数据源,参数二为Connection对象
rs.Open "Select * From sample", conn, 2, 2
%>
'连结foxpro文件
<%
' 建立Connection 对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Visual FoxPro Driver};"
SourceType = "SourceType=DBC;"
DBPath = "SourceDB=" & Server.MapPath( "Dbf/Sample.dbc" )
' 调用Open 方法连接数据库
conn.Open Driver & SourceType & DBPath
Set rs = Server.CreateObject("ADODB.Recordset")
' 打开数据源,参数二为Connection对象
rs.Open "Select * From sample", conn, 2, 2
%>
'连结excel文件
<%
' 建立Connection对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Excel Driver (*.xls)};"
DBPath = "DBQ=" & Server.MapPath( "Sample.xls" )
' 调用Open 方法连接数据库
conn.Open Driver & DBPath
Set rs = Server.CreateObject("ADODB.Recordset")
' 打开数据源,参数二为Connection对象
rs.Open "Select * From [成绩单$]", conn, 2, 2
%>
'连结txt文件
<%
' 建立Connection 对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Text Driver (*.txt; *.csv)};"
DBPath = "DBQ=" & Server.MapPath( "Text" )
' 调用Open 方法连接数据库
conn.Open Driver & DBPath
Set rs = Server.CreateObject("ADODB.Recordset")
' 打开数据源,参数二为Connection对象
rs.Open "Select * From sample.txt", conn, 2, 2
%>
SELECT语法:(基本)
*************************************************************
**********************************************************
SELECT [DISTINCT]
(column [{, column } ] )| *
FROM table [ { , table} ]
[ORDER BY column [ASC] | [DESC
[{ , column [ASC] | [DESC } ] ]
WHERE predicate [ { logical-connector predicate } ];
------------------------------------------------------
INSERT语法:
INSERT INTO table
[(column { ,column})]
VALUES
(columnvalue [{,columnvalue}]);
------------------------------------------------------
UPDATE语法:
UPDATE table
SET column = value [{, column = value}]
[ WHERE predicate [ { logical-connector predicate}]];
------------------------------------------------------
DELETE语法:
DELETE FROM table
[WHERE predicate [ { logical-connector predicate} ] ];
------------------------------------------------------