首先調(diào)用adodb.connection對(duì)象中的openSchema函數(shù),這樣會(huì)得到一個(gè)Recordset,其中每一條“紀(jì)錄”對(duì)應(yīng)著數(shù)據(jù)庫(kù)中的一張表,“紀(jì)錄”的每個(gè)“字段”包含了對(duì)應(yīng)表的某方面信息。其中TABLE_NAME字段包含了對(duì)應(yīng)表的名稱(chēng)
可以把本功能寫(xiě)成一個(gè)函數(shù),函數(shù)的處理過(guò)程描述如下:
首先調(diào)用adodb.connection對(duì)象中的openSchema函數(shù),這樣會(huì)得到一個(gè)Recordset,其中每一條“紀(jì)錄”對(duì)應(yīng)著數(shù)據(jù)庫(kù)中的一張表,“紀(jì)錄”的每個(gè)“字段”包含了對(duì)應(yīng)表的某方面信息。其中TABLE_NAME字段包含了對(duì)應(yīng)表的名稱(chēng)
然后遍歷這個(gè)Recordset,如果“當(dāng)前紀(jì)錄”的TABLE_NAME字段的值和要查找的表的名字一樣,證明要查找的表存在。
函數(shù)如下所示:
復(fù)制代碼代碼如下:
function check_gived_DataTable_exist_or_not(connect_object,name_of_gived_DataTable)
Do_gived_DataTable_exist=false
Const adSchemaTables=20 '表明想要得到數(shù)據(jù)庫(kù)中“表(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)這個(gè)函數(shù)執(zhí)行后,會(huì)得到“數(shù)據(jù)庫(kù)中表(table)和視圖(view)的集合”,這是一個(gè)ADODB.Recordset類(lèi)型的數(shù)據(jù)。
if RecordSet_about_table_and_view_in_DataBase("TABLE_TYPE")="TABLE"這句話(huà)把檢查范圍縮小為“表(table)”。