This function can be written as a function, and the process of the function is described as follows:
First call the OpenSchema function in the Adodb.connection object, which will get a recordset where each "record" corresponds to a table in the database, and each "field" in the "record" contains some aspect of the corresponding table. Where the table_name field contains the name of the corresponding table
The recordset is then traversed, and if the value of the TABLE_NAME field in the current record is the same as the name of the table being looked for, it proves that the table being looked for exists.
The function looks like this:
Copy 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 a collection of tables and 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
Comments:
Connect_object.openschema (adSchemaTables) This function is executed with a "collection of tables and views" in the database, which is a adodb.recordset type of data.
If Recordset_about_table_and_view_in_database ("table_type") = "table" The sentence reduces the scope of the check to "tables".