ASP与SQL2005数据库在浏览器上显示数据库的数据
1.ASP与sql2005连接浏览器时整个浏览器时白屏。2.测试数据源成功。
3.显示SQl2005数据时错误代码HTTP500。
4.没有配置Reporting Services 配置会不会影响显示数据:
代码如下;
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<! --#include file="stu.asp"-->
<html xmlns="http://www.
<head>
<style type="text/css">
< !--
td{font-size:12px; COLER: #000000; font:Verdana; line-height:14pt
}
.STYLE1 {color: #FFFFFF}
</style>
<title>显示学生的信息</title>
</head>
<h3> 学生信息浏览</h3>
<%
Action=request.QueryString(Action"")
DeleId=request.QueryString("id")
select Case Action
Case "Dale_Score"
conn.execute "Dalete From student
response.Redirect "index.asp"
Case "Save_Score"
set rs2=server.CreateObject("ADODB.recordset")
rs2.open "select * from Student
rs2("Sname")=request("Sname")
rs2("Ssex")=request("Ssex")
rs2("Sage")=request("Sage")
rs2("Sdept")=request("Sdept")
rs2.update
rs.close
set rs2=nothing
response.Redirect "index.asp"
case ""
%>
<body>
<table width="98%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolorlight="#666666" bordercolordark="#ffffff" >
<tr>
<td bgcolor="#666666" align=center><font color="#FFFFFF">学号</td>
<td bgcolor="#666666" align=center><font color="#FFFFFF">姓名</td>
<td bgcolor="#666666" align=center><font color="#FFFFFF">性别</td>
<td bgcolor="#666666" align=center><font color="#FFFFFF">年龄</td>
<td bgcolor="#666666" align=center><font color="#FFFFFF">所在的系</td>
<td bgcolor="#666666" align=center><font color="#FFFFFF">操作</td>
</tr>
<%
set rs=server.CreateObject("ADODB.recordset")
rs.open "select * from student",conn,1,1
If rs.bof and rs.eof Then
response.Write "<tr><td colspan=7 align=center> 数据库中未找到相应的记录!</td>
Else
Do while not rs.eof
%>
<tr>
<td bgcolor="#666666" align=center ><%=rs("Sno") %></td>
<td bgcolor="#666666" align=center ><%=rs("Sname") %></td>
<td bgcolor="#666666" align=center ><%=rs("Ssex") %></td>
<td bgcolor="#666666" align=center ><%=rs("Sage") %></td>
<td bgcolor="#666666" align=center ><%=rs("Sdept") %></td>
<font color="#FF0000">删除</td><% //提供删除记录的连接%>
</tr>
<%
rs.movenext
loop
End If
rs.close
set rs=nothing
End select
%>
<tr>
<td colspan="7"><input name="Add_Stu" type="button" value="增加新成员" onclick="location.href='Add.asp'" ></td>
</tr>
</table>
</body>
</html>
连接SQl2005代码:
<title>学生信息查询网站</title>
<link rel="stylesheet" href="..\inc\sty.css" type="text/css" >
</head>
<body topmargin="0" leftmargin="0">
<%
Dim SqlDatabaseName,SqlPassword,SqlUsername,SqlLocalName,ConnStr,Conn
SqlDatabaseName = "stu" 'SQL数据库名
SqlPassword = "sss" 'SQL数据库用户密码
SqlUsername = "sss" 'SQL数据库用户名
SqlLocalName = "127.0.0.1" 'SQL主机IP地址(本地可用“127.0.0.1”或“(local)”,非本机请用真实IP)
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
if err.number<>0 then
err.clear
conn.close
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
if err then
err.clear
conn.close
set conn=nothing
response.write "数据库连接出错!"
Response.End
end if
end if
sub CloseConn()
conn.close
set conn=nothing
end sub
%>
</body>
</html>