请老鸟帮忙写个连接SQL并列出所有记录的ASP源码,效果就好比在查询分析器上输入select * from 表 就这么简单的效果
就这个效果我搞半天了,
我的服务器ip是192.168.1.5,uid=sa,password=123
数据库名也是123,表是xszhiliao
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
dim conn
dim connstr
on error resume next
connstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123;Initial Catalog=123;Data Source=192.168.1.5" '不好意思,这字符串是直接在VB的代码里粘过来用的,反正不出错就行
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
mySQL="select * from xszhiliao"
set rs=conn.execute(mySQL)
%>
<table border=1><tr>
<% '设置表头
for each whatever in rs.fields%>
<td><b><%=whatever.name%></B></TD>
<% next %>
</tr>
<% ' 显示所有记录
DO UNTIL rs.eof %>
<tr>
<% for each whatever in rs.fields
thisfield=whatever.value
if isnull(thisfield) then
thisfield=shownull
end if
if trim(thisfield)="" then
thisfield=showblank
end if%>
<td valign=top><%=thisfield%></td>
<% next %>
</tr>
<%rs.movenext
LOOP%>
</table>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%>