急:asp调用sql数据库并显示指定字段

发布网友 发布时间:2024-10-24 06:25

我来回答

2个回答

热心网友 时间:2024-10-26 18:36

<%
public function OpenDB()
on error resume next
dim sConn,Conn '存放数据库联接的信息
sConn="PROVIDER=SQLOLEDB;driver={sql server};server=.;database=数据库名;uid=sa;pwd=数据库密码"
set Conn=server.CreateObject("adodb.Connection")
Conn.Open sConn

if err.number<>0 then
Response.Write "数据库连接出错!"
Response.End
else
set OpenDB=Conn
end if
end function
%>

<%
Set Conn=OpenDB()

set rs=server.createobject("adodb.recordset")
sql="select * from user"
rs.Open sql,Conn,1,1

if not rs.eof then

for i=1 to recordcount

response.write rs("company ") '输出公司

next

end if

rs.close
set rs=nothing

conn.close
set conn=nothing
%>

热心网友 时间:2024-10-26 18:38

set conn=server.createobject("adodb.connection")
connstr="driver=sqlserver;server=localhost;uid=root;pwd=;database=xxw_data"
conn.open connstr

set rs=server.createobject("adodb.recordset")

rs.open "select company form user",conn,1,1

do while not rs.eof

response.write rs("company")&"<br />"

rs.movenext

loop

if rs.eof then exit do

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com