First call the openSchema function in the adodb.connection object, which will get a Recordset, in which each "record" corresponds to a table in the database, and each "field" of the "record" contains certain aspects of the information of the corresponding table. The TABLE_NAME field contains the name of the corresponding table
This function can be written as a function, and the processing process of the function is described as follows:
First call the openSchema function in the adodb.connection object, which will get a Recordset, in which each "record" corresponds to a table in the database, and each "field" of the "record" contains certain aspects of the information of the corresponding table. The TABLE_NAME field contains the name of the corresponding table
Then traverse the Recordset. If the value of the TABLE_NAME field of the "current record" is the same as the name of the table to be searched, it proves that the table to be searched exists.
The function looks like this:
Copy the code code as follows:
function check_gived_DataTable_exist_or_not(connect_object,name_of_gived_DataTable)
Do_gived_DataTable_exist=false
Const adSchemaTables=20 'Indicates that you want to get the "collection of tables (tables) and views (views)" in the database
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
Note:
After the connect_object.openSchema(adSchemaTables) function is executed, you will get "a collection of tables and views in the database", which is ADODB.Recordset type data.
if RecordSet_about_table_and_view_in_DataBase("TABLE_TYPE")="TABLE" narrows the scope of the check to "table".