Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Database File calling skills
(1) In fact, no matter which Access database you change to, the steps for connecting to the database and reading table records are the same. The variable is the name of the database file and the table name, therefore, you can set the 3rd ~ Line 13 is rewritten as a function and coexist into a file, such as ADOFunctions. asp. If you want to open a database file in the future, set the file ADOFunctions. asp installation (include). The code is as follows:
'Variable Filename is the database file Name, and variable Table Name is the Table Name.
Function GetRecordset (FileName, TableName)
'Use ASP Connection object to open the database
Set objConn = Server. CreateObject ("ADODB. Connection ")
ObjConn. ConnectionString = "Provider = Microsoft. Jet. OLEDB.4.0 ;"&_
"Data Source =" & Server. MapPath ("Filename ")
'Read the table records and store them in the Record set object "objRS"
Set objRS = Server. CreateObject ("ADODB. Recordset ")
ObjRS. Open TableName, objConn, adOpenKeyset, adLockOptimistic, adCmdTable
According to the code above, the function name is GetRecordSet, and its return value is the Record set object instance that stores table records. It is saved as the file name ADOFunctions. asp. Now, you can use this file to read records of any database file. For example, the programming for reading databases can be simplified as follows:
<! -- # Include file = "adovbs. inc" -->
<! -- # Include file = "ADOFunctions. asp" -->
'Call the GetRecordset function to obtain a Record set object instance F and assign it to the variable objRS.
Set objRS = GetRecordset ("Friend. mdb", "data ")
'Display the records indicated by the current pointer on the browser
If Not objRS. EOF Then
Response. Write "no.:" & objRS ("no.") & "<BR>"
Response. Write "name:" & objRS ("name") & "<BR>"
Response. Write "gender:" & objRS ("gender") & "<BR>"
Response. Write "All qualified records have been displayed at the end of the database"
'Close the database connection and release the object instance
Set objRS = Nothing
Set objConn = Nothing
Therefore, Set objRS = GetRecordset ("Friend. you can call any Access database file by changing the database name and table name in mdb "," data "). Of course, note that, the field names of each table in the database must match.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.