Access也来查询分析

做过access网站的相信会有一个烦恼,数据库托管在别人的服务器,要操作比较麻烦,想查查数据是否异常也不方便,于是简单地实现一个"查询分析器",方便操作.
<!--#include file="Include/fConnStr.asp"-->
<!--上面是连接数据库,不多说-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>SQL</title>
</head>
<%
Select Case Request("btnLevel")
Case "Main"
Case Else
   Call zMain()
End Select
%>

<body>
<%
'==============================
'主画面
'==============================
Sub zMain()
Dim strSQL,strCode,Column,RsCount
Dim intNum
RsCount=0
strSQL   =Trim(Request.Form("SQL"))
strCode   =Trim(Request.Form("Code"))
%>
<table cellspacing="0" cellpadding="0" width="100%" border="1" class="tableBorder" style="border-collapse: collapse">
<form action="" method="post">
<tr>
   <td>
    <textarea name="SQL" rows="15" cols="150"><%=strSQL%></textarea><br />
    <input type="text" name="Code" />[*如要更新数据,请输入]<br />
    <input type="submit" value="提交" />
   </td>
</tr>
</form>
</table>
<%
If strSQL <> "" Then
If LCase(Left(strSQL,6))="select" Then
   Set rstMain = Server.CreateObject("ADODB.Recordset")
   rstMain.Open strSQL,fGetCnnStr,1,1
   Column =rstMain.Fields.Count
   RsCount =rstMain.RecordCount
Else
   If LCase(strCode)="execute" Then '这里设置你的"密码",如要做SELECT以外的操作,则需要输入,防止误操作
    fGetCnnStr.execute(strSQL)
   End If
End If
End If
%>
<%
If RsCount>0 Then
%>
<table cellspacing="0" cellpadding="0" width="100%" border="1" class="tableBorder" style="border-collapse: collapse">
<tr align="center">
   <%For intNum=0 To Column-1%>
   <th><%=rstMain.Fields(intNum).Name%></th>
   <%Next%>
</tr>
<%While Not rstMain.Eof%>
<tr align="center">
   <%For intNum=0 To Column-1%>
   <td><%=rstMain(intNum)%></td>
   <%Next%>
</tr>
<%
rstMain.MoveNext
WEnd
%>
</table>
<%Else%>
<table cellspacing="0" cellpadding="0" width="100%" border="1" class="tableBorder" style="border-collapse: collapse">
<tr align="center">
   <td>没有记录</td>
</tr>
</table>
<%
End If
%>

<%
End Sub
%>
</body>
</html>

 

做INS,UPD,DEL这些就简单了.查询方面:主要就用到以下两句:

Column =rstMain.Fields.Count '获取本句SQL一共有多少字段
rstMain.Fields(intNum).Name '这句是获取搜索的field名.

实现非常简单,但比较实用.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值