asp怎样读取数据库

2025-04-06 04:46:58
推荐回答(3个)
回答1:


<%
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open"select * from blog_content",conn,1,1
if rs.eof and rs.bof then
response.write ("没有数据")
else
response.write ("

")
for i=1 to 50 '打开数据从1到50循环'
response.write ("") '这句话显示日志的题目链接'
rs.movenext
if rs.eof then exit for
next
response.write ("
")&rs("日志字段名")&("
")
end if
rs.close:set rs=nothing
%>

<%
id=request("id") '这儿的ID是获取上页面的ID号'
if not isnumeric id then id = "" '这儿是判断ID是否数字,如果不是则ID为空'
pwd=request("pwd") '这儿是获取密码'
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open"select * from blog_content where log_id="&id&"",conn,1,1 '这儿是打开log_id与ID相等的数据'
if rs.eof then
response.write ("没有找到相关文章")
else
if pwd = "" or pwd=rs("log_pwd") then
response.write rs("日志字段")
rs.close:set rs=nothing
else
%>
" method="post" name="pwd">



<%
end if
end if
%>

没测试,不知道对不对,如果还有问题请加QQ148087061

回答2:

asp读取数据库代码如下:
dim conn,connstr,rs,sql

set conn = Server.CreateObject("Adodb.Connection")
connstr = "Provider=SQLOLEDB;data source=127.0.0.1;initial catalog=DBname;uid=username;pwd=password"
conn.open connstr
set rs = Server.CreateObject("Adodb.RecordSet")
sql = "select id from table"
rs.open sql,conn,1,1
if not rs.eof
response.write "ID为:" & rs("id")
end if
rs.close
conn.close
set conn=nothing
以上代码为把数据库中的id显示出来

回答3:

ADO