一个简单的SQL语句执行器
2001-12-24 10:21:56 来源:WEB开发网核心提示:大至分为三个文件:ljmdb.asp(连接库文件)、entice.asp(sql语句执行主界面)、entice2.asp(select记录集)ljmdb.asp<%set conndb=server.createobject("ADODB.CONNECTION")constr="PR
大至分为三个文件:ljmdb.asp(连接库文件)、entice.asp(sql语句执行主界面)、entice2.asp(select记录集)
====================================ljmdb.asp
<%
set conndb=server.createobject("ADODB.CONNECTION")
constr="PRovider=microsoft.jet.oledb.4.0;data
source="&server.mappath("/aspsky.myip.org/entice.mdb")
conndb.open constr
%>
'这是连接access的,把数据库的地址改成你自己的地址就行了
====================================entice.asp
<%
if left(trim(request("sqllanguage")),6)="select" then
%>
<script language=javascript>
window.open("entice2.asp?sql=<%=request("sqllanguage")%>","","height=450,width=600,resizable=yes,
scrollbars=yes,status=no,toolbar=no,menubar=no,location=no")
</script>
<%
end if
%>
<!--#include file=ljmdb.asp-->
<%
%>
<HTML>
<Title>SOL语句执行示例 </Title>
<style type="text/CSS">
<!--
body { font-size: 12px}
table { font-size: 12px}
-->
</style>
<Body Bgcolor=#009999>
<%
sqllanguage=Request("sqllanguage")
%>
<Form Name="FormPst" Method="Post" Action="entice.asp">
<div align="center"><FieldSet> <Legend>请输入SQL语句</Legend> 指令:
<Input type="text" name="sqllanguage" Size=60>
<Input type="Submit" Value="送出">
</FieldSet> </div>
</form>
<Hr>
SQL 语句执行情况:
<%
if sqllanguage<>Empty then
On Error Resume Next
conndb.Execute(sqllanguage)
if err.number="0" then
message1="执行成功"
response.write message1
else
message1=err.description
response.write message1
err.clear
end if
end if
%>
<%
set rstable=conndb.openSchema(20)
rstable.movefirst
%>
<table width="95%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#000000">
<%
do while not rstable.eof
if rstable("table_type")="TABLE" then
%>
<tr bgcolor="#006400">
<td width="18%" nowrap><font color="#FFFFFF">数据库中的表名</font></td>
<td width="82%" nowrap> <font color="#FFFFFF">
<%
response.write rstable("table_name")
%>
</font></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="18%" nowrap>该表中的所有字段</td>
<td width="82%" nowrap>
<%
set rstobj=server.createobject("adodb.recordset")
rstsql="select * from "&rstable("table_name")
rstobj.open rstsql,conndb,1
for i=0 to rstobj.fields.count-1
response.write rstobj(i).name&"|"
next
rstobj.close
set rstobj=nothing
%>
</td>
</tr>
<%
end if
rstable.movenext
loop
rstable.close
set rstable=nothing
%>
</table>
</Body>
</HTML>
<%
conndb.close
set conndb=nothing
%>
=====================================entice2.asp
<Title>select查询器====entice</Title>
<style type="text/css">
<!--
body { font-size: 12px}
table { font-size: 12px}
-->
</style>
<Body Bgcolor=#009999>
<!--#include file=ljmdb.asp-->
<%
rstsql=request("sql")
response.write "你的查询语句为:"&rstsql&"
下面是您所查询的记录集"
set rstobj=server.createobject("adodb.recordset")
rstobj.open rstsql,conndb,1
response.write ",共查到"&rstobj.recordcount&"条记录"
fcount=rstobj.fields.count
response.write "<table width='98%' border='0' cellspacing='1' cellpadding='3' align='center'
bgcolor='#000000'><tr bgcolor='#006400'>"
for i=0 to fcount-1
response.write "<td><font color='ffffff'>"&rstobj(i).name&"</font></td>"
next
response.write "</tr>"
do while not rstobj.eof
response.write "<tr bgcolor='#cccccc'>"
for i=0 to fcount-1
response.write "<td>"&rstobj(i)&"</td>"
next
response.write "</tr>"
rstobj.movenext
loop
response.write "</table>"
rstobj.close
set rstobj=nothing
conndb.close
set conndb=nothing
%>
====================================ljmdb.asp
<%
set conndb=server.createobject("ADODB.CONNECTION")
constr="PRovider=microsoft.jet.oledb.4.0;data
source="&server.mappath("/aspsky.myip.org/entice.mdb")
conndb.open constr
%>
'这是连接access的,把数据库的地址改成你自己的地址就行了
====================================entice.asp
<%
if left(trim(request("sqllanguage")),6)="select" then
%>
<script language=javascript>
window.open("entice2.asp?sql=<%=request("sqllanguage")%>","","height=450,width=600,resizable=yes,
scrollbars=yes,status=no,toolbar=no,menubar=no,location=no")
</script>
<%
end if
%>
<!--#include file=ljmdb.asp-->
<%
%>
<HTML>
<Title>SOL语句执行示例 </Title>
<style type="text/CSS">
<!--
body { font-size: 12px}
table { font-size: 12px}
-->
</style>
<Body Bgcolor=#009999>
<%
sqllanguage=Request("sqllanguage")
%>
<Form Name="FormPst" Method="Post" Action="entice.asp">
<div align="center"><FieldSet> <Legend>请输入SQL语句</Legend> 指令:
<Input type="text" name="sqllanguage" Size=60>
<Input type="Submit" Value="送出">
</FieldSet> </div>
</form>
<Hr>
SQL 语句执行情况:
<%
if sqllanguage<>Empty then
On Error Resume Next
conndb.Execute(sqllanguage)
if err.number="0" then
message1="执行成功"
response.write message1
else
message1=err.description
response.write message1
err.clear
end if
end if
%>
<%
set rstable=conndb.openSchema(20)
rstable.movefirst
%>
<table width="95%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#000000">
<%
do while not rstable.eof
if rstable("table_type")="TABLE" then
%>
<tr bgcolor="#006400">
<td width="18%" nowrap><font color="#FFFFFF">数据库中的表名</font></td>
<td width="82%" nowrap> <font color="#FFFFFF">
<%
response.write rstable("table_name")
%>
</font></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="18%" nowrap>该表中的所有字段</td>
<td width="82%" nowrap>
<%
set rstobj=server.createobject("adodb.recordset")
rstsql="select * from "&rstable("table_name")
rstobj.open rstsql,conndb,1
for i=0 to rstobj.fields.count-1
response.write rstobj(i).name&"|"
next
rstobj.close
set rstobj=nothing
%>
</td>
</tr>
<%
end if
rstable.movenext
loop
rstable.close
set rstable=nothing
%>
</table>
</Body>
</HTML>
<%
conndb.close
set conndb=nothing
%>
=====================================entice2.asp
<Title>select查询器====entice</Title>
<style type="text/css">
<!--
body { font-size: 12px}
table { font-size: 12px}
-->
</style>
<Body Bgcolor=#009999>
<!--#include file=ljmdb.asp-->
<%
rstsql=request("sql")
response.write "你的查询语句为:"&rstsql&"
下面是您所查询的记录集"
set rstobj=server.createobject("adodb.recordset")
rstobj.open rstsql,conndb,1
response.write ",共查到"&rstobj.recordcount&"条记录"
fcount=rstobj.fields.count
response.write "<table width='98%' border='0' cellspacing='1' cellpadding='3' align='center'
bgcolor='#000000'><tr bgcolor='#006400'>"
for i=0 to fcount-1
response.write "<td><font color='ffffff'>"&rstobj(i).name&"</font></td>"
next
response.write "</tr>"
do while not rstobj.eof
response.write "<tr bgcolor='#cccccc'>"
for i=0 to fcount-1
response.write "<td>"&rstobj(i)&"</td>"
next
response.write "</tr>"
rstobj.movenext
loop
response.write "</table>"
rstobj.close
set rstobj=nothing
conndb.close
set conndb=nothing
%>
- ››SQL Server 2008 R2 下如何清理数据库日志文件
- ››sqlite 存取中文的解决方法
- ››SQL2005、2008、2000 清空删除日志
- ››SQL Server 2005和SQL Server 2000数据的相互导入...
- ››sql server 2008 在安装了活动目录以后无法启动服...
- ››简单直观易用 Win 8触屏操作更高效
- ››sqlserver 每30分自动生成一次
- ››简单的Windows 8账户切换(无需重启)
- ››sqlite 数据库 对 BOOL型 数据的插入处理正确用法...
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
更多精彩
赞助商链接