1. ASP与Access数据库连接:
复制代码 代码如下:
<%
dim conn,mdbfile
mdbfile=server.mappath("数据库名称.mdb")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=数据库密码;dbq="&mdbfile
%>
最常用的asp与access连接的字符串函数
复制代码 代码如下:
Call OpenConn
Sub OpenConn()
On Error Resume Next
If DataBaseType = 1 Then
ConnStr="Provider = Sqloledb; User ID = " & datauser & "; Password = " & databasepsw & "; Initial Catalog = " & databasename & "; Data Source = " & dataserver & ";"
Else
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(DBPath)
End If
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then Err.Clear:Set conn = Nothing:Response.Write "数据库连接出错,请检查Conn.asp文件中的数据库参数设置。":Response.End
CollcetConnStr ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(CollectDBPath)
End Sub
<%
dim conn
set conn=server.createobject("ADODB.connection")
con.open "PROVIDER=SQLOLEDB;DATA SOURCE=SQL服务器名称或IP地址;UID=sa;PWD=数据库密码;DATABASE=数据库名称
%>
建立记录集对象:
set rs=server.createobject("adodb.recordset")
rs.open SQL语句,conn,3,2
3. SQL常用命令使用方法:
(1) 数据记录筛选:
sql="select * from 数据表 where 字段名=字段值 order by 字段名 "
sql="select * from 数据表 where 字段名 like ‘%字段值%‘ order by 字段名 "
sql="select top 10 * from 数据表 where 字段名 order by 字段名 "