Search Tools Links Login

Display SQL Results


Display a page that allows you to type in a SQL Query statement, and display the results in HTML Table format.
The number of field parameters and field names are immaterial. It will display the results in an easy to read format. Great for customer reports.
The Code will not allow an Update or Delete query.

Original Author: Eugene

Inputs

You will have to provide the connection to your database. There are examples in the code.

Returns

An HTML Page

Code

<%
' Open Connection to the database
dim Connect
set Connect = Server.CreateObject("ADODB.Connection")
REM - Un-Rem one of the connect statements depending on your data
' connection method, and change the phyisical path if necessary
'1. ODBC
'strConn = "DSN=ASP-Forum; uid=;password=;"
'2. SQL-OLEDB
'strConn = "PROVIDER=SQLOLEDB; uid=;password=;Initial Catalog=ASPForum;"
'3. ADO-Access
'strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:inetpubwwwrootaspforumforum.mdb"
'4. OLE 4.0
'strConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=d:inetpubwwwrootaspforumforum.mdb"
Connect.Open strConn
sSQL = request.form("Sequel")
%>










SQL Statement:



      

  



<%
if left(ucase(trim(sSQL)), 6) = "UPDATE" or left(ucase(trim(sSQL)), 6) = "DELETE" or left(ucase(trim(sSQL)), 4) = "DROP" then
%>







Function Not Allowed from this view



<%
elseif sSQL > "" then
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sSQL, Connect
flds = rs.Fields.Count
if not (rs.bof and rs.eof) then
%>







Searching for selected data...



<%
dim sColor(1)
toggle = 1
sColor(0) = ""
sColor(1) = "bgcolor=#eeeeee"
response.write "" & vbCrLf
response.write "" & vbCrLf
For i = 0 To flds - 1
response.write ""
Next
response.write vbCrLf & ""
rs.movefirst
Do While Not rs.EOF
toggle = 1 - toggle
response.write "" & vbCrLf
For i = 0 To flds - 1
response.write ""
Next
response.write vbCrLf & ""
rs.MoveNext
Loop
end if
rs.Close
Set rs = Nothing
response.write vbcrlf & "
" & rs.Fields(i).Name & "
" & rs.Fields(i).Value & " 
"
end if
%>

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 89 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.