连接数据库
<%
DBPath=server.MapPath("database/data.mdb")
set conn=server.createobject("ADODB.CONNECTION")
cnstr = "Driver={Sql server};server=localhost;database=sfrs;uid=sa;pwd=; "
cnstr = "Provider=MSDASQL;Driver={SQL Server};server=localhost;Database=;Uid=sa;Pwd=;"
cnstr= "Driver={Mircosoft Access Driver(*.mdb)};DBQ="&server.mappath("database/data.mdb")
cnstr="Driver={microsoft access driver (*.mdb)};dbq="&DBPath&";UID=user;PWD=password;"
cnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库名;"
cnstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库名;Jet OLEDB:Database Password=数据库密码;"
conn.open cnstr
sub closeconn(conn)
conn.close
set conn=nothing
end sub
%>
数据添加,删除,修改,查询
conn.execute("Insert into table(fields1,fields2)values('"&fields1&"','"&fields2&"')")
conn.execute("Delete from table where id=”&Did&”")
conn.execute("Update table set fields1='"&fields1&"', fields2='"&fields2&"' where id=”&eid&”")
SQL=”Select * from table where 查询条件”
用记录集添加记录 (修改,删除)
add=request("add")
set rs=server.createobject("adodb.recordset")
if add=1 then
sql="select * from student where (ID is null)"
rs.open sql,i_conn,1,3
rs.addnew (修改:将sql条件改为要修改的记录,少掉rs.addnew)
(删除:将sql条件改为要删除的记录, rs.delete)
rs("zd1")=Request.form("edz1")
rs("zd2")=Request.form("sex")
rs("zd3")=Request.form("edz3")
rs("zd4")=Request.form("edz4")
rs("zd5")=Request.form("edz5")
rs("zd6")=Request.form("edz6")
rs("zd7")=Request.form("edz7")
rs("zd8")=Request.form("edz8")
'
rs("zd9")=Request.form("edz9")
rs.update
rs.close
分页显示要点
<%
set rs=server.CreateObject("adodb.recordset")
sql="select * from Table where "
rs.open sql,conn,1,3
rs.pagesize = 12
mypagesize = rs.pagesize
page=clng(request("page"))
if page<=1 or page="" then
page=1
firstv=true
else
firstv=false
end if
if page>=rs.pagecount then
page=rs.pagecount
lastv=true
else
lastv=false
end if
%>
<% if not rs.eof then
rs.absolutepage = page
do while not rs.eof and mypagesize>0 and i<=11
%>
取出数据
<%i=i+1
rs.movenext
loop
else%>
如果没有数据,显示没有数据信息
<%End if%>
<%if firstv then %>『首 页』<%else%>『<a href="?page=1">首 页</a>』<%end if%>
<%if firstv then %>【上一页】<%else%>
【<a href="?page=<%=page-1%>">上一页</a>】<%end if%>
<%if lastv then %>【下一页】<%else%>
【<a href="?page=<%=page+1%>">下一页</a>】<%end if%>
<%if lastv then %>『末 页』<%else%>
『<a href="?page=<%=rs.pagecount%>">末 页</a>』<%end if%>
rs.recordcount 共有多少条记录。
rs.pagecount
共有多少页
page
为当前页