一个简单的SQL语句执行器

大至分为三个文件:ljmdb.asp(连接库文件)、entice.asp(sql语句执行主界面)、entice2.asp(select记录集)

====================================ljmdb.asp

1   
2set conndb=server.createobject("ADODB.CONNECTION")   
3constr="provider=microsoft.jet.oledb.4.0;data   
4  
5source="&server.mappath("/aspsky.myip.org/entice.mdb")   
6conndb.open constr   

'这是连接access的,把数据库的地址改成你自己的地址就行了

====================================entice.asp

1   
2if left(trim(request("sqllanguage")),6)="select" then   
1<script language="javascript">   
2window.open("entice2.asp?sql=```
3=request("sqllanguage")
4```","","height=450,width=600,resizable=yes,   
5  
6scrollbars=yes,status=no,toolbar=no,menubar=no,location=no")   
7</script>
1   
2end if   
1   
1<html>
2<title>SOL语句执行示例 </title>
3<style type="text/css">   
4<!--   
5body { font-size: 12px}   
6table { font-size: 12px}   
7\-->   
8</style>
9<body bgcolor="#009999">   

sqllanguage=Request("sqllanguage")

1<form action="entice.asp" method="Post" name="FormPst">
2<div align="center"><fieldset> <legend>请输入SQL语句</legend> 指令:   
3<input name="sqllanguage" size="60" type="text"/>
4<input type="Submit" value="送出"/>
5</fieldset> </div>
6</form>
7<hr/>   
8SQL 语句执行情况:   
9  

if sqllanguage&lt;&gt;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

1  
2  
3  

set rstable=conndb.openSchema(20)
rstable.movefirst

1<table align="center" bgcolor="#000000" border="0" cellpadding="3" cellspacing="1" width="95%">   

do while not rstable.eof
if rstable("table_type")="TABLE" then

1<tr bgcolor="#006400">
2<td nowrap="" width="18%"><font color="#FFFFFF">数据库中的表名</font></td>
3<td nowrap="" width="82%"> <font color="#FFFFFF">   

response.write rstable("table_name")

1</font></td>
2</tr>
3<tr bgcolor="#CCCCCC">
4<td nowrap="" width="18%">该表中的所有字段</td>
5<td nowrap="" width="82%">   

set rstobj=server.createobject("adodb.recordset")
rstsql="select * from "&amp;rstable("table_name")
rstobj.open rstsql,conndb,1
for i=0 to rstobj.fields.count-1
response.write rstobj(i).name&amp;"|"
next
rstobj.close
set rstobj=nothing

1</td>
2</tr>   

end if
rstable.movenext
loop
rstable.close
set rstable=nothing

1</table>
2</body>
3</html>
1   
2conndb.close   
3set conndb=nothing   

=====================================entice2.asp

1<title>select查询器====entice</title>
1<style type="text/css">   
2<!--   
3body { font-size: 12px}   
4table { font-size: 12px}   
5\-->   
6</style>
1<body bgcolor="#009999">
2<!--#include file=ljmdb.asp-->   

rstsql=request("sql")
response.write "你的查询语句为:"&amp;rstsql&amp;"
下面是您所查询的记录集"
set rstobj=server.createobject("adodb.recordset")
rstobj.open rstsql,conndb,1
response.write ",共查到"&amp;rstobj.recordcount&amp;"条记录"
fcount=rstobj.fields.count
response.write "<table align="center" bgcolor="#000000" border="0" cellpadding="3" cellspacing="1" width="98%"><tr bgcolor="#006400">"
for i=0 to fcount-1
response.write "<td><font color="ffffff">"&amp;rstobj(i).name&amp;"</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>"&amp;rstobj(i)&amp;"</td>"
next
response.write "</tr>"
rstobj.movenext
loop
response.write "</table>"
rstobj.close
set rstobj=nothing
conndb.close
set conndb=nothing

Published At
Categories with Web编程
Tagged with
comments powered by Disqus