首页 >> 读书频道 >> 电脑 >> ADSI使用ASP来实现通用的对数据库控制编程
 
· 使用ADSI开发NT目录
· ADSI及其在WEB上的
· 透过 ASP 修改 NT
· 如何通过编程为组添加成员
· 优化Web数据库页面
· 判断文章中文字符数量
· 检查来访IP是否合法的实
· 如何写出优秀的ASP应用
· 编程优化杂谈
· 什么才是提高ASP性能的
· 如何提高WEB程序的效率
· 什么才是提高ASP性能的
 
· 素质教育在美国
· 全唐诗卷四十六
· 韩剧《布拉格恋人》剧情介
· 夜航船[作者:明·张岱]
· 局外人[作者:韩·可爱淘
· 现场流行病学
· 源氏物语[日本:紫式部]
· 红楼梦:120回全本[清
· 武林寓言故事
· 2006高考录取规则
· 首批中国世界名牌产品和2
· 济南美食大全
 
· (出租)中动商场部分及写
· (出租)中动动漫基地&#
· 喜剧学院
· 《善德女王》剧情介绍
· 魔女18号 剧情
· 丑女无敌剧情介绍
· 魔女幼熙剧情介绍
· 龙游天下剧情介绍
· 震撼世界的七日剧情介绍
· 静静的白桦林剧情介绍
· 心情日记—老公今天我想对
· 旗舰剧情介绍
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/

ADSI使用ASP来实现通用的对数据库控制编程


查看有无更新版本

关键字:ASP 2006-8-28

 

非常有价值的代码,下面的代码是使用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
End If
table.MoveNext
Wend
response.write "</SELECT>"
response.write "<INPUT type=submit name=table value=go>"
If strEnableDeleteTable = True Then
response.write " <input type=submit name=DeleteTable value=delete>"
End If
response.write "</form>"
response.write "<form action=""" & file & "?DatabaseName=" & Server.URLEncode(dsn_name) & """ method=post>"
response.write "<table><tr>"
response.write "<td colspan=2><font face=Verdana,Arial size=2 color=""#ff0000"">Add New Table into " & dsn_name & "</font></td>"
response.write "</tr><tr>"
response.write "<th><font face=Verdana,Arial size=2>Table Name:</font></th>"
response.write "<td><input type=text name=NewTableName></td>"
response.write "</tr><tr>"
response.write "<td colspan=2 align=center><input type=submit name=AddNewTable value=""Add New Table""></td></tr></table>"
response.write "</form><hr>"
End If
If table_name <> "" AND Request("DeleteTable")="" Then
response.write "<form action=""" & file & "?DatabaseName=" & Server.URLEncode(dsn_name) & "&TableName=" & table_name & """ method=post>"
response.write "<table border=2 align=center cellpadding=2 cellspacing=2>"
response.write "<tr>"
response.write "<th colspan=4 align=left><font face=Verdana,Arial size=3 color=teal>" & table_name & "</font></th>"
response.write "</tr><tr><th><font face=Verdana,Arial size=2>Field Name</font></th>"
response.write "<th><font face=Verdana,Arial size=2>Field Size</font></th>"
response.write "<th><font face=Verdana,Arial size=2>Field DataType</font></th>"
response.write "<th><font face=Verdana,Arial size=2>Delete</font></th></tr>"
SQL = "SELECT * FROM " & table_name
Set rs = con.Execute(SQL)
For each fldName in rs.Fields
response.write "<tr>"
response.write "<td><font face=Verdana,Arial size=2 color=""#000000"">" & fldName.Name & "</font></td>"
response.write "<td><font face=Verdana,Arial size=2 color=""#000000"">" & fldName.DefinedSize & "</font></td>"
response.write "<td><font face=Verdana,Arial size=2 color=""#000000"">" & GetTypeName(fldName.Type) & "</font></td>"
response.write "<td align=center><input type=checkbox name=DeleteCol value=""" & fldName.Name & """></td>"
response.write "</tr>"
Next
response.write "<tr><td colspan=4 align=center><input type=submit name=DeleteColumn value=""Delete Selected Column""></td></tr>"
response.write "</table>"
response.write "<table><tr>"
response.write "<td colspan=2><font face=Verdana,Arial size=2 color=""#ff0000"">Add New Field into " & table_name & "</font></td>"
response.write "</tr><tr>"
response.write "<th><font face=Verdana,Arial size=2>Field Name:</font></th>"
response.write "<td><input type=text name=""NewFieldName""></td>"
response.write "</tr><tr>"
response.write "<th><font face=Verdana,Arial size=2>Field Type:</font></th>"
response.write "<td><select name=""NewFieldType"">"
For i = 0 to uBound(field_value)
response.write "<option value=""" & field_value(i) & """>" & field_display(i)
Next
response.write "</select></td></tr>"
response.write "<tr><td colspan=2 align=center><input type=submit name=AddNewField value=""Add New Field""></td></tr></table>"
response.write "</form>"
End If
response.write "</center></BODY></HTML>"
Function GetTypeName(id)
Select Case id
Case "3"
GetTypeName = "Number"
Case "200"
GetTypeName = "Text"
Case "129"
GetTypeName = "Text"
Case "201"
GetTypeName = "Memo"
Case "6"
GetTypeName = "Currency"
Case "11"
GetTypeName = "Yes/No"
Case "5"
GetTypeName = "Number"
Case "7", "133","134","135"
GetTypeName = "Date/Time"
Case Else
GetTypeName = id
End Select
End Function
Sub SelectDataType(it)
response.write "<SELECT NAME=EditColName>"
For i = 0 to UBOUND(field_value)
If field_display(i) = it Then
response.write "<option value=""" & field_value(i) & """ selected>" & field_display(i)
Else
response.write "<option value=""" & field_value(i) & """>" & field_display(i)
End If
Next
response.write "</Select>"
End Sub
%>

ADSI使用ASP来实现通用的对数据库控制编程

[ 1 ]
ADSI使用ASP来实现通用的对数据库控制编程 num

打印本页 关闭

关于我们版权声明本站导航友情连结作品演示 TOP↑