Displays the names of all tables in the SQL database (with the delete feature)

Source: Internet
Author: User
Tags table name
<%
' Define your SQL info here
STRSQLDSN = "xxxx"
Strsqlusername = "sa"
Strsqlpassword = ""

' This is where we connect to our SQL Server
Set adoconn = Server.CreateObject ("ADODB. Connection ")
ConnectionString = "dsn=" & Strsqldsn & "Uid=" & Strsqlusername & ";p wd=" & Strsqlpassword & ""
Adoconn.open ConnectionString
Set adors = Server.CreateObject ("ADODB. Recordset ")

' Now we'll just difine a couple things
Showblank = ""
Shownull = "-null-"

If request.querystring ("action") = "Del" Then
Delete_data
Else
If request.querystring ("table") <> "Then
' A table has been selected
Page_head
Display_table_names
If request.querystring ("msg") = "deleted" Then
Response.Write ("<p><br></p>")
Response.Write ("<font color=" "#FF0000" ><b> "successfully delete data </b></font>")
Else
Response.Write ("<p><br></p>")
End If
Display_table_info
Else
' No table has been selected.
Page_head
Display_table_names
End If
End If

Sub Page_head
%>
<HTML>
<HEAD>
<title>sql viewer</title>
<body alink= #0663bf leftmargin= "0" link= "#0663bf" topmargin= "0" vlink= "#0663bf" marginheight= "0"

Marginwidth= "0" >
</HEAD>
<p><br></p>
<%
End Sub

Sub Delete_data
strSQL = "Delete from" & Request.QueryString ("table") & "Where id=" "&

Request.QueryString ("id") & "'"
Set adors = Adoconn.execute (strSQL)
strURL = "index.asp?table=" & Request.QueryString ("table") & "&msg=deleted"
Response.Redirect (strURL)
End Sub

Sub Display_table_names
Response.Write ("<div align=" "Center" "><center>" & VbCrLf)
Response.Write ("" & VbCrLf)
Response.Write ("<table border=" "1" "cellpadding=" "0" "cellspacing=" "0" "width=" "36%" "

Bordercolor= "" #9b9180 ">" & vbCrLf)
Response.Write ("<tr bgcolor=" "#9b9180" ">" & vbCrLf)
Response.Write ("<td width=" "100%" "><p align=" "Center" "><font

Color= "" #FFFFFF "" ><strong>sql viewer</strong></font></td> "& vbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("<tr bgcolor=" "#dcd8d1" ">" & vbCrLf)
Response.Write ("<td width=" "100%" "><div align=" "Center" "><center><table border=" "0")

Cellpadding= "" 0 "" "& VbCrLf)
Response.Write ("cellspacing=" "0" "width=" "100%" ">" & vbCrLf)
Response.Write ("<tr>" & VbCrLf)
Response.Write ("<td width=" "100%" "> </td>" & vbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("<tr>" & VbCrLf)
Response.Write ("<td width=" "100%" "Nowrap><center> <select size=" "1" "

Name= "" Table "" style= "" Font-family:verdana; Font-size:8pt ""

Onchange= "" Top.location.href=this.options[this.selectedindex].value "" > "& vbCrLf)
Response.Write ("<option Selected value> Please select Table name to view .</option>" & vbCrLf)
strSQL = "SELECT name from sysobjects WHERE xtype = ' U ' and (not (id) = 133575514) Order

By name "
Set adors = Adoconn.execute (strSQL)
Do as not adors.eof
Response.Write "<option value=" "Index.asp?table=" & Adors ("name") & "" > "&

Adors ("name") & "</option>"
Adors.movenext
Loop
Response.Write ("</select> </center></td>" & vbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("<tr>" & VbCrLf)
Response.Write ("<td width=" "100%" "> </td>" & vbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("</table>" & VbCrLf)
Response.Write ("</center></div></td>" & VbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("</table>" & VbCrLf)
Response.Write ("</center></div>" & VbCrLf)
End Sub

Sub Display_table_info
Response.Write ("<div align=" "Center" "><center>" & VbCrLf)
Response.Write ("<table border=" "1" "cellpadding=" "0" "cellspacing=" "0" "width=" "36%" "

Bordercolor= "" #9b9180 ">" & vbCrLf)
Response.Write ("<tr bgcolor=" "#9b9180" ">" & vbCrLf)
Response.Write ("<td width=" "100%" "><p align=" "Center" "><font

Color= "" #FFFFFF "" ><strong>sql </strong></font></td> "& vbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("<tr bgcolor=" "#dcd8d1" ">" & vbCrLf)
Response.Write ("<td width=" "100%" "><div align=" "Center" "><center><table border=" "0")

Cellpadding= "" 0 "" "& VbCrLf)
Response.Write ("cellspacing=" "0" "width=" "100%" ">" & vbCrLf)
Response.Write ("<tr>" & VbCrLf)
Response.Write ("<td></td>" & VbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("<tr>" & VbCrLf)
' This selects the table which we want to use.
Strsql= "SELECT * from" & Request.QueryString ("table") & ""
Set Adors=adoconn.execute (strSQL)
' Now lets start the table
Response.Write ("<table border=" "1" "><tr>" & VbCrLf)
' This'll find all of the fields in that table and write them out
For each fieldname in Adors.fields
Response.Write ("<td><b><font size=" "2" ">" & fieldname.name & "</font></B>< /TD> ")
NEXT ' fieldname
Response.Write ("<td><b><font size=" "2" "> Delete </font></B></TD>")
Response.Write ("</tr>" & VbCrLf)
Do UNTIL adors.eof
Response.Write ("<tr>")
For each fieldname in Adors.fields
Strfieldvalue=fieldname.value
Strfield=fieldname.name
IF IsNull (Strfieldvalue) THEN
Strfieldvalue=shownull
End IF
IF trim (strfieldvalue) = "" THEN
Strfieldvalue=showblank
End IF
IF Strfield = "id" OR Strfield = "id" THEN
Strrecordid = Strfieldvalue
End IF
Response.Write ("<td valign=top><font size=" "2" ">" & Strfieldvalue &

"</font></td>" & VbCrLf)
NEXT
Response.Write ("<td valign=top><font size=" "2" "><a href=" "Index.asp?table=" &

Request.QueryString ("table") & "&id=" & Strrecordid & "&action=del" "> Delete </a></font ></td> "&

VBCRLF)
Adors.movenext
LOOP
Response.Write ("</table>")
Adors.close
Response.Write ("</tr>" & VbCrLf)
Response.Write ("<tr>" & VbCrLf)
Response.Write ("<td></td>" & VbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("</table>" & VbCrLf)
Response.Write ("</center></div></td>" & VbCrLf)
Response.Write ("</tr>" & VbCrLf)
Response.Write ("</table>" & VbCrLf)
Response.Write ("</center></div>" & VbCrLf)
End Sub
%>


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.