求asp网页查询access数据库的编程代码

2025-01-01 11:09:40
推荐回答(3个)
回答1:

<%‘连接数据库
db = "md.mdb" '前提时保证数据库文件和本文件在统一目录
connstr = "DBQ=" + server.mappath(""&db&"") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
Set conn = server.CreateObject("ADODB.CONNECTION")
conn.Open connstr
set rs = server.CreateObject("adodb.recordset")
'分页函数
sub pcfinal_page(pageMark)'以pageMark作为分页标志
action = "http://" & request.servervariables("http_host") & request.servervariables("script_name")
query = Split(request.servervariables("query_string"), "&")
For Each x in query
a = Split(x, "=")
If StrComp(a(0), pageMark, vbTextCompare) <> 0 Then
temp = temp & a(0) & "=" & a(1) & "&"

End If
Next
response.Write("

")
If page<= 1 Then
response.Write ("首页 上一页 ")
Else
response.Write("首页 上一页 ")
End If
If page>= maxpage Then
response.Write ("下一页 尾页 ")
Else
response.Write("下一页 尾页 ")
End If
response.Write("["&page&"/"&maxpage&"页] [共"&allpage&"条记录] 转到第
")
end sub
'列出信息
sql = "select * from mingdan order by id"
rs.open sql,conn,1,1
%>








<%
page = request("page")
If Not IsNumeric(page) Or page = "" Then
page = 1
Else
page = CInt(page)
rs.pagesize = 25
maxpage=rs.pagecount
allpage=rs.Recordcount
End If
If page<1 Then
page = 1
ElseIf page>maxpage Then
page = maxpage
End If
if page = 1 then
specialID = 1
else
specialID = (page-1)*rs.pagesize
end if
rs.AbsolutePage = Page
If page = maxpage Then
x = allpage - (maxpage -1) * iPageSize
Else
x = iPageSize
End If
if rs.eof then
response.Write("暂无内容!")
else
rs.absolutepage = page
for q=1 to rs.pagesize
if not rs.eof then
%>







<%Rs.movenext
end if
next%>
序号 姓名 性别 身份证号码 年龄
<%=rs("ID")%> <%=rs("xm")%> <%=Rs("xb")%> <%=Rs("sfzh")%> <%=Rs("nl")%>

<%
call pcfinal_page("page")
end if
%>

回答2:

估计你的是下拉选择姓名查询或身份证号查询,后面跟个长条框吧?
点击查询后跳转到查询页面,获取传递的参数。
////1代表选择姓名,2代表身份证。Content是后面自己填写的,譬如名字或身份证号码
dim ID,Content
ID=Request.Form("id")
Content=Request.Form("content")
set Rs=Server.CreateObject("ADODB.RecordSet")
if(ID=1) then
Sql="select * from mingdan where xm like ’%" & Content & "%’"
else if(ID=2) then
Sql="select * from mingdan where sfzh="&Content&""
end if
Rs.open sql,conn,1,1
do while not Rs.eof
.......
下面应该自己会写了吧

回答3:

你自己动手吧!ACCESS中有SQL查询语句,填好条件---查看语句,复制粘贴到ASP表单对话语句的变量里面就成了。