A simple SQL statement executor

Source: Internet
Author: User
Statement | Execution is divided into three files: ljmdb.asp (Connection library file), entice.asp (SQL statement Execution main interface), entice2.asp (select Recordset)

====================================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
%>
' This is connected to access, you can change the address of the database to your own address.

====================================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 Statement Execution Example </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> Please enter SQL statement </Legend> directive:
<input type= "text" name= "Sqllanguage" size=60>
<input type= "Submit" value= "Send Out" >
</FieldSet> </div>
</form>
<Hr>
SQL Statement Execution:

<%
If Sqllanguage<>empty Then
On Error Resume Next
Conndb. Execute (Sqllanguage)
If err.number= "0" Then
message1= "executed successfully"
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= "border=" 0 "cellspacing=" 1 "cellpadding=" 3 "align=" center "bgcolor=" #000000 ">
<%
Do as not rstable.eof
If Rstable ("table_type") = "Table" Then
%>
<tr bgcolor= "#006400" >
&LT;TD width= "18%" Nowrap><font color= "#FFFFFF" > the table name in the database </font></td>
&LT;TD width= "82%" nowrap> <font color= "#FFFFFF" >
<%

Response.Write rstable ("table_name")
%>
</font></td>
</tr>
<tr bgcolor= "#CCCCCC" >
&LT;TD width= "18%" nowrap> all fields in the table </td>
&LT;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 Query ====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 "Your query statement is:" &rstsql& "
The following is the recordset you are querying
Set Rstobj=server.createobject ("Adodb.recordset")
Rstobj.open rstsql,conndb,1
Response.Write ", a total of" &rstobj.recordcount& "records"
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 as not rstobj.eof
Response.Write "<tr bgcolor= ' #c



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.