日期:2013-03-27  浏览次数:20953 次

非常有价值的代码,下面的代码是使用ADSI 的对象数据库概念编制成的,只要你理解了我在前面文章说的东西,下面的代码只不过是ADSI牛刀小试而已只要有了下面这个思路,以后不论是对付什么数据库,就是不知道数据库的结构也不用害怕了。
<%
'--- define DSN names in array
database_list=Array("dsn_1","dsn_2","dsn_3")
'--- enable deleting table? -- Carefull!!
strEnableDeleteTable = False
'---- end declaration

'---- do not change code below this line ---------------------------------------------
field_value=Array("Integer","Double","char(255)","Memo","Date","Currency","YesNo")
field_display=Array("Integer","Number","Text","Memo","Date/Time","Currency","Yes/No")

dsn_name = Request("DatabaseName")
If Not dsn_name = "" Then
Set con = Server.CreateObject("ADODB.Connection")
con.Open "DSN=" & dsn_name
End If
table_name = Request("TableName")

If Request("AddNewTable")<>"" Then
If Request("NewTableName") <> "" Then
SQL = "CREATE TABLE " & Request("NewTableName") & " (fldAuto Counter)"
con.Execute(SQL)
End If
End If
If Request("AddNewField")<>"" Then
If request("NewFieldName") <> "" Then
SQL = "ALTER TABLE " & table_name & " ADD " & request("NewFieldName") & " " & request("NewFieldType") & " NULL"
con.Execute(SQL)
End If
End If
If Request("DeleteTable")<>"" Then
SQL = "DROP TABLE " & Request("TableName")
Con.Execute(SQL)
End If
If Request("DeleteColumn")<>"" Then
For Each item In Request("DeleteCol")
SQL = "ALTER TABLE " & Request("TableName") & " DROP " & item
con.Execute(SQL)
Next
End If
'----- file name--------------------------------------------------------
file = Request.ServerVariables("SCRIPT_NAME")
file = strReverse(file)
pos = Instr(file,"/")
file = Left(file, pos-1)
file = strReverse(file)
%>

<%
response.write "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2 Final//EN"">"
response.write "<HTML><HEAD><TITLE>Database Control</TITLE></HEAD>"
response.write "<BODY bgcolor=""#FFFFFF""><br><br><center>"

'------------------------------------------------------------
response.write "<form action=""" & file & """ method=post>"
response.write "<b><font face=verdana size=3 color=""#008080""><u>Total Database Control</u></font></b><br><br>"
response.write "<font face=Verdana,Arial size=2><b>Database Name: </b></font>"
response.write "<select name=""databasename"">"
For i = 0 to uBound(database_list)
If database_list(i) = Request("databasename") Then
response.write "<option value=""" & database_list(i) & """ selected>" & database_list(i)
Else
response.write "<option value=""" & database_list(i) & """>" & database_list(i)
End If
Next
response.write "</select> "
response.write "<input type=submit name=GoDatabase value=go>"
response.write "<hr></form>"
'-------------------------------------------------------------
response.write "<form action=""" & file & "?DatabaseName=" & Server.URLEncode(dsn_name) & """ method=post>"

If dsn_name<>"" Then
Set table = con.OpenSchema (20)
response.write "<font face=Verdana,Arial size=2>Table Names in " & dsn_name & ": </font><SELECT NAME=TableName>"
While Not table.EOF
tblName = table("Table_Name")
If Left(tblName,4) <> "MSys" AND Left(tblName,3) <> "sys" AND Left(tblName,4) <> "RTbl" Then
If tblName = table_name Then
response.write "<OPTION VALUE=""" & tblName & """ selected>" & tblName
Else
response.write "<OPTION VALUE=""" & tblName & """>" & tblName
End If