<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
'新建数据库
if request("act")="CreateDB" then
PathName=trim(request("PathName"))
DbVersion= trim(request("DbVersion"))
if PathName="" then
response.write("")
end if
Call FindPathName(PathName)
Call CreateDB(PathName,DbVersion)
end if
'压缩数据库
if request("act")="CompactDB" then
PathName=trim(request("PathName"))
DbVersion=trim(request("DbVersion"))
if PathName="" then
response.write("")
end if
Call FindPathName(PathName)
Call ComPactDB(PathName,DbVersion)
end if
'删除数据库
if request("act")="DeleteDB" then
PathName=trim(request("PathName"))
if PathName="" then
response.write("")
end if
Call FindPathName(PathName)
Call DeleteDB(PathName)
end if
' 查询所有数据表名称
if request("act")="FindTableList" then
PathName=trim(request("PathName"))
if PathName="" then
response.write("")
end if
Call FindPathName(PathName)
Call FindTableList(PathName,TableListString)
end if
' 查询数据表名称
if request("act")="FindTableName" then
PathName=trim(request("PathName"))
TableName=cstr(trim(request("TableName")))
TableName1=cstr(trim(request("TableName1")))
if PathName="" then
response.write("")
end if
if TableName="" then
response.write("")
end if
Call FindPathName(PathName)
Call FindTableName2(PathName,TableName)
end if
'更新数据表名称
if request("act")="AlterTableName" then
PathName=trim(request("PathName"))
TableName=cstr(trim(request("TableName")))
TableName1=cstr(trim(request("TableName1")))
if PathName="" then
response.write("")
end if
if TableName="" then
response.write("")
end if
if TableName1="" then
response.write("")
end if
Call FindPathName(PathName)
Call FindTableName(PathName,TableName)
Call FindTableName1(PathName,TableName1)
Call AlterTableName(PathName,TableName,TableName1)
end if
'删除数据表名称
if request("act")="DropTableName" then
PathName=trim(request("PathName"))
TableName=cstr(trim(request("TableName")))
if PathName="" then
response.write("")
end if
if TableName="" then
response.write("")
end if
Call FindPathName(PathName)
Call FindTableName(PathName,TableName)
Call DropTableName(PathName,TableName)
end if
'查询数据表字段
if request("act")="FindTableColumnList" then
PathName=trim(request("PathName"))
TableName=cstr(trim(request("TableName")))
if PathName="" then
response.write("")
end if
if TableName="" then
response.write("")
end if
Call FindPathName(PathName)
Call FindTableName(PathName,TableName)
Call FindTableColumnList(PathName,TableName)
end if
Sub CreateDB(PathName,DbVersion)
on error resume next
select case DbVersion
case "97"
DbVersion1 = "3.51"
case "2000"
DbVersion1 = "4.0"
end select
Set Cat = Server.CreateObject("ADOX.Catalog")
call Cat.Create("Provider=Microsoft.Jet.OLEDB." & DbVersion1 & ";Data Source=" & server.MapPath(PathName))
if err then
response.write("")
Response.end
else
response.write("")
response.End()
end if
End Sub
Sub FindPathName(PathName)
on error resume next
x=0
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.fileexists(server.MapPath(PathName))=true then
x=1
set fso=nothing
if err then
response.write("")
Response.end
else
if x=0 then
response.write("")
response.End()
end if
end if
end if
End Sub
'查询指定名称的数据表,找到了继续,找不到返回
Sub FindTableName(PathName,TableName)
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(PathName)
set objConn=server.createobject("Adodb.connection")
objConn.open strConn
rem x=0 表示不存在,x=1 表示存在
set rsSchema=objConn.openSchema(20)
rsSchema.movefirst
x=0
Do Until rsSchema.EOF
if rsSchema("TABLE_TYPE")="TABLE" then
if rsSchema("TABLE_NAME")=tablename then
x=1
exit do
end if
end if
rsSchema.movenext
Loop
if x=0 then
response.write("")
response.End()
end if
set objConn=nothing
End Sub
'查询指定名称的数据表,找到了返回,找不到继续
Sub FindTableName1(PathName,TableName)
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(PathName)
set objConn=server.createobject("Adodb.connection")
objConn.open strConn
rem x=0 表示不存在,x=1 表示存在
set rsSchema=objConn.openSchema(20)
rsSchema.movefirst
x=0
Do Until rsSchema.EOF
if rsSchema("TABLE_TYPE")="TABLE" then
if rsSchema("TABLE_NAME")=tablename then
x=1
exit do
end if
end if
rsSchema.movenext
Loop
if x=1 then
response.write("")
response.End()
end if
set objConn=nothing
End Sub
'查询指定的数据表
Sub FindTableName2(PathName,TableName)
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(PathName)
set objConn=server.createobject("Adodb.connection")
objConn.open strConn
rem x=0 表示不存在,x=1 表示存在
set rsSchema=objConn.openSchema(20)
rsSchema.movefirst
x=0
Do Until rsSchema.EOF
if rsSchema("TABLE_TYPE")="TABLE" then
if rsSchema("TABLE_NAME")=tablename then
x=1
exit do
end if
end if
rsSchema.movenext
Loop
if x=1 then
response.write("")
response.End()
else
response.write("")
response.End()
end if
set objConn=nothing
End Sub
'查询指定数据库中的所有数据表
Sub FindTableList(PathName,TableListString)
TableListString=""
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(PathName)
set objConn=server.createobject("Adodb.connection")
objConn.open strConn
rem x=0 表示不存在,x=1 表示存在
set rsSchema=objConn.openSchema(20)
rsSchema.movefirst
x=0
Do Until rsSchema.EOF
if rsSchema("TABLE_TYPE")="TABLE" then
x=x+1
TableListString=TableListString&rsSchema("TABLE_NAME")&";"
end if
rsSchema.movenext
Loop
if x>0 then
response.write("")
response.End()
else
response.write("")
response.End()
end if
set objConn=nothing
End Sub
'删除数据库
Sub DeleteDB(PathName)
on error resume next
x=0
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.fileexists(server.MapPath(PathName))=true then
fso.deletefile(server.MapPath(PathName))
set fso=nothing
if err then
response.write("")
Response.end
else
response.write("")
response.End()
end if
end if
End Sub
'修改数据表名称
Sub AlterTableName(PathName,TableName,TableName1)
'Dim MyTable,MyField ,pro
On Error resume next
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(PathName)
set Conn=server.createobject("Adodb.connection")
Conn.open strConn
set mydb=server.createobject("adox.catalog")
set mytable=server.createobject("adox.table")
set myfield =server.createobject("adox.column")
MyDB.ActiveConnection =Conn
For Each MyTable In MyDB.Tables
if MyTable.Name=TableName then
MyTable.Name=TableName1
exit for
end if
Next
conn.close
set Conn=nothing
if err then
response.write("")
Response.end
else
response.write("")
Response.end
end if
End Sub
'删除数据表名称
Sub DropTableName(PathName,TableName)
'Dim MyTable,MyField ,pro
On Error resume next
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(PathName)
set Conn=server.createobject("Adodb.connection")
Conn.open strConn
set mydb=server.createobject("adox.catalog")
set mytable=server.createobject("adox.table")
set myfield =server.createobject("adox.column")
MyDB.ActiveConnection =Conn
For Each MyTable In MyDB.Tables
if MyTable.Name=TableName then
MyDB.Tables.delete(TableName)
exit for
end if
Next
conn.close
set Conn=nothing
if err then
response.write("")
Response.end
else
response.write("")
Response.end
end if
End Sub
Sub CompactDB(PathName, DbVersion)
on error resume next
strPathName = left(server.MapPath(PathName),instrrev(server.Mappath(PathName),"/"))
Set fso = CreateObject("Scripting.FileSystemObject")
Set Engine = CreateObject("JRO.JetEngine")
If DbVersion = 97 Then
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath(PathName), _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathName & "temp.mdb;" _
& "Jet OLEDB:Engine Type=" & 4
Else
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath(PathName), _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathName & "temp.mdb"
End If
fso.CopyFile strPathName & "temp.mdb",server.MapPath(PathName)
fso.DeleteFile(strPathName & "temp.mdb")
Set fso = nothing
Set Engine = nothing
if err then
response.write("")
Response.end
else
response.write("")
Response.end
end if
end sub
Sub FindTableColumnList(PathName,TableName)
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(PathName)
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open ConnStr
Const adSchemaTables = 20
adSchemaColumns = 4
Set rstSchema = oConn.OpenSchema(adSchemaColumns)
response.write "
"
response.write "Table name | field name | field type | is nullable | field size |
"
'tablename=""
Do Until rstSchema.EOF
if rstSchema("Table_name") =tablename then
response.write ""
response.write rstSchema("Table_name")
response.write " | "& rstschema("column_Name") & " | "
select case rstschema("data_type")
case 130
if rstschema("CHARACTER_MAXIMUM_LENGTH") = 1073741823 then
response.write "Memo"
else
response.write "Text"
end if
case 135
response.write "Date/Time"
case 3
response.write "Long Integer"
case 11
response.write "Yes/No"
case 131
response.write "Currency"
case else
response.write rstschema("data_type")
end select
response.write " | " & rstschema("is_nullable") & " | "
if rstschema("CHARACTER_MAXIMUM_LENGTH") <> 1073741823 then
response.write rstschema("CHARACTER_MAXIMUM_LENGTH")
else
response.write " "
end if
response.write " |
"
end if
rstSchema.MoveNext
Loop
response.write "
"
response.Write("
")
response.End()
end sub
%>