檢查access數(shù)據(jù)庫中是否存在某個名字的表的asp代碼
更新時間:2009年06月29日 00:06:37 作者:
首先調用adodb.connection對象中的openSchema函數(shù),這樣會得到一個Recordset,其中每一條“紀錄”對應著數(shù)據(jù)庫中的一張表,“紀錄”的每個“字段”包含了對應表的某方面信息。其中TABLE_NAME字段包含了對應表的名稱
可以把本功能寫成一個函數(shù),函數(shù)的處理過程描述如下:
首先調用adodb.connection對象中的openSchema函數(shù),這樣會得到一個Recordset,其中每一條“紀錄”對應著數(shù)據(jù)庫中的一張表,“紀錄”的每個“字段”包含了對應表的某方面信息。其中TABLE_NAME字段包含了對應表的名稱
然后遍歷這個Recordset,如果“當前紀錄”的TABLE_NAME字段的值和要查找的表的名字一樣,證明要查找的表存在。
函數(shù)如下所示:
function check_gived_DataTable_exist_or_not(connect_object,name_of_gived_DataTable)
Do_gived_DataTable_exist=false
Const adSchemaTables=20 '表明想要得到數(shù)據(jù)庫中“表(table)和視圖(view)的集合”
set RecordSet_about_table_and_view_in_DataBase=connect_object.openSchema(adSchemaTables)
Do Until RecordSet_about_table_and_view_in_DataBase.EOF
if RecordSet_about_table_and_view_in_DataBase("TABLE_TYPE")="TABLE" then
if RecordSet_about_table_and_view_in_DataBase("TABLE_NAME")= name_of_gived_DataTable then
Do_gived_DataTable_exist=true
exit do
end if
end if
RecordSet_about_table_and_view_in_DataBase.movenext
Loop
check_gived_DataTable_exist_or_not=Do_gived_DataTable_exist
end function
注釋:
connect_object.openSchema(adSchemaTables)這個函數(shù)執(zhí)行后,會得到“數(shù)據(jù)庫中表(table)和視圖(view)的集合”,這是一個ADODB.Recordset類型的數(shù)據(jù)。
if RecordSet_about_table_and_view_in_DataBase("TABLE_TYPE")="TABLE"這句話把檢查范圍縮小為“表(table)”。
首先調用adodb.connection對象中的openSchema函數(shù),這樣會得到一個Recordset,其中每一條“紀錄”對應著數(shù)據(jù)庫中的一張表,“紀錄”的每個“字段”包含了對應表的某方面信息。其中TABLE_NAME字段包含了對應表的名稱
然后遍歷這個Recordset,如果“當前紀錄”的TABLE_NAME字段的值和要查找的表的名字一樣,證明要查找的表存在。
函數(shù)如下所示:
復制代碼 代碼如下:
function check_gived_DataTable_exist_or_not(connect_object,name_of_gived_DataTable)
Do_gived_DataTable_exist=false
Const adSchemaTables=20 '表明想要得到數(shù)據(jù)庫中“表(table)和視圖(view)的集合”
set RecordSet_about_table_and_view_in_DataBase=connect_object.openSchema(adSchemaTables)
Do Until RecordSet_about_table_and_view_in_DataBase.EOF
if RecordSet_about_table_and_view_in_DataBase("TABLE_TYPE")="TABLE" then
if RecordSet_about_table_and_view_in_DataBase("TABLE_NAME")= name_of_gived_DataTable then
Do_gived_DataTable_exist=true
exit do
end if
end if
RecordSet_about_table_and_view_in_DataBase.movenext
Loop
check_gived_DataTable_exist_or_not=Do_gived_DataTable_exist
end function
注釋:
connect_object.openSchema(adSchemaTables)這個函數(shù)執(zhí)行后,會得到“數(shù)據(jù)庫中表(table)和視圖(view)的集合”,這是一個ADODB.Recordset類型的數(shù)據(jù)。
if RecordSet_about_table_and_view_in_DataBase("TABLE_TYPE")="TABLE"這句話把檢查范圍縮小為“表(table)”。
相關文章
ASP轉換格林威治時間函數(shù)DateDiff()應用
ASP提供了一個叫 DateDiff() 的函數(shù),這個函數(shù)可以返回一個時間差的秒,那就是說我們放進去一個格林威治標準時間與現(xiàn)在的時間對比一下返回秒就OK2014-06-06
巧用FileSystem組件實現(xiàn)WEB應用中的本地特定打印的方法
巧用FileSystem組件實現(xiàn)WEB應用中的本地特定打印的方法...2007-04-04
windows2003下使用asp WScript.Shell的設置方法
在windows2000下,IIS默認設置是可以web和可執(zhí)行程序通信的。但是在2003下IIS關于這方面的服務是禁止的。2007-12-12

