ASP code to check for a table with a name in the Access database application tips

Source: Internet
Author: User
Tags access database
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".
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.