Most ASP applications cannot do without access and operations to databases, so we should abstract the access operations of the database part separately and encapsulate them into a separate class. If the language used supports inheritance, you can encapsulate such a class and then inherit it at the data operation layer. Below is a class I wrote for ACCESS database access, which was optimized for ACCESS. However, due to the lack of sufficient application testing, there may still be unknown bugs and application restrictions. The main code is as follows:
<%
ClassOledbPrivateIDataPath
PrivateIConnectionStringPrivateConn
PrivateCmd
PrivateParam
PrivateRsPublicPropertyLetDataPath(ByValValue)
IDataPath=Value
IConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Server.MapPath(IDataPath)
EndPropertyPublicPropertyGetDataPath()
DataPath=IDataPath
EndPropertyPublicPropertyLetConnectionString(ByValValue)
IConnectionString=Value
EndPropertyPublicPropertyGetConnectionString()
ConnectionString=IConnectionString
EndPropertyPublicFunctionOpenConn()
IfConn.State=adStateClosedThen
Conn.OpenConnectionString
EndIf
SetOpenConn=Conn
EndFunctionPublicFunctionInsert(ByValSql,ByValValues)
OpenConn()
Rs.OpenSql,Conn,3,3,adCmdText
Rs.AddNew
Dimi,l
l=UBound(Values)
Fori=1Tol+1
Rs(i)=Values(i-1)
Next
Rs.Update
Insert=Rs(0)
EndFunctionPublicFunctionExecute(ByValSql)
OpenConn()
SetExecute=Conn.Execute(Sql)
EndFunctionPublicFunctionExecuteScalar(ByValSql)
DimiRs:SetiRs=Execute(Sql)
IfNotiRs.BOFTThenExecuteScalar=iRs(0)
EndFunctionPublicFunctionExecuteNonQuery(ByValSql)
OpenConn()
CallConn.Execute(Sql,ExecuteNonQuery)
EndFunctionPublicFunctionInsertSp(ByValSql,ByValParams)
OpenConn()
Rs.OpenSql,Conn,3,3,adCmdStoredProc
Rs.AddNew
Dimi,l
l=UBound(Params)
Fori=1Tol+1
Rs(i)=Params(i-1)
Next
Rs.Update
InsertSp=Rs(0)
EndFunctionPublicFunctionExecuteSp(ByValSpName,ByValParams)
WithCmd
Set.ActiveConnection=OpenConn()
.CommandText=SpName
.CommandType=&H0004