请老鸟帮忙写个连接SQL并列出所有记录的ASP源码,效果就好比在查询分析器上输入select * from 表 就这么简单的效果

monica888 2005-04-18 07:17:27
就这个效果我搞半天了,
我的服务器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
%>
...全文
237 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovebeyondforever 2005-04-18
  • 打赏
  • 举报
回复
<%@ language=javascript %>
<!--#include file="adojavas.inc" -->
<!--#include file="OnePage.asp" -->
<html><head><title></title></head>
<body>
<% conn = Server.CreateObject("ADODB.Connection");
conn.Open ("webdata","sa","123");
rs = Server.CreateObject("ADODB.Recordset");
sql = "xszhiliao";rs.Open (sql, conn, 1);
rs.PageSize = 2;
if (0 == Request("Page").count){Page = 1;}
else{Page = parseInt(Request("Page"))}
if (Page < 1){Page = 1;}
if (Page > rs.PageCount){Page = rs.PageCount;}
ShowOnePage(rs, Page);%>
<div ALIGN="right">
<hr>
<form Action="??????.asp" Method="GET">
<% if (!(1==Page)){Response.Write("<A HREF=?????????.asp?Page=1>第一页</A>");
Response.Write("<A HREF=?????.asp?Page=" + (Page-1) + ">上一页</A>");}
if (!(rs.PageCount==Page))
{Response.Write("<A HREF=?????.asp?Page=" + (Page+1) + ">下一页</A>");
Response.Write("<A HREF=???????.asp?Page=" + rs.PageCount + ">最后一页</A>");}%>

<p>输入页数:<input TYPE="TEXT" Name="Page" SIZE="3"> 页数:<font COLOR="Red"><%=Page%>/<%=rs.PageCount%></font>
</p>

</div></body></html>

/////////////////////////////////////
OnePage.asp
/////////////////////////////////////
<%
function ShowOnePage( rs, Page )
{
Response.Write("<CENTER><table border=4 bordercolor=orange>");
Response.Write("<TR bgcolor=orange>");
Response.Write("<TD><font color=white><b>编号</b></font></TD>");

var i;
for (i=0; i<rs.Fields.Count; i++)
{
Response.Write("<TD><font color=white><b>" + rs.Fields(i).Name + "</b></font></TD>");
}
Response.Write("</TR>");

rs.AbsolutePage = Page;
var iPage;
for (iPage=1; iPage<=rs.PageSize; iPage++)
{
if (!rs.EOF)
{
Response.Write("<TR align=middle>");
RecNo = (Page - 1) * rs.PageSize + iPage;
Response.Write("<TD>" + RecNo + "</TD>");
for(i=0; i<rs.Fields.Count; i++)
{
Response.Write("<TD>" + rs.Fields(i).Value + "</TD>");
}
Response.Write("</TR>");
rs.MoveNext();
}
}
Response.Write("</TABLE></CENTER>");
}
%>

这个应该可以!

jbright 2005-04-18
  • 打赏
  • 举报
回复
晕 不解!你已经做到了,还问什么啊?
monica888 2005-04-18
  • 打赏
  • 举报
回复
我就是想在asp页面显示sql里面的数据,不知道源码怎么写
windancer 2005-04-18
  • 打赏
  • 举报
回复
问题呢?
monica888 2005-04-18
  • 打赏
  • 举报
回复
帮帮忙

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧