The ASP database access class is made.

xiaoxiao2021-03-06  14

The ASP database access class is made.

<% '----------------------------------------------- ------------------------- '********************** *** Database - Table - Module Class 2.0 ********************************************************** *********************************************************** ******************** The private variable: p_dbconnection: database link, p_tablename: Table name 'attribute: dbconnstring: Database linked string' error: Error code errordesc : Error message Version: Version information 'Property1: Field 1 Property2: Field 2 Property3: Field 3' Property4: Field 4 Property5: Field 5 Property6: Field 6 'Property7: Field 7 Property8: Field 8 Property9: Field 9' method: ' DBOPEN () 'dbclose ()' INSERT () Directly add information stored in the properties field to the database 'addnew () directly stores information stored in the properties field to the database in the database' delete () DELETE statement delete record / needs to open database connection parameters: SQL WHERE clause 'update () Use Update statement update record / needs to open Database connection parameters: SQL WHERE clause' Fill () Take 1 record / need to open Databases with SELECT Connection parameters: SQL WHERE clause '' Usage: '1 Copy this mode to new file, filename changes' 2 changes by the table name' 3 Change Property "3 Change Property to the corresponding field in the table (with Replace, Directly replaced Property1, do not select WHOLE WORD INLY '4 Adjusting the get and let'5 of each field to handle error code' '--------------- Application example - ------- 'set tb1 = new TB_TABLENAME' Instantian 'TB1.DBOPEN' Open DB '' --- addNew --- 'tb1.propety 1 = "SDFSD"' to the attribute assignment '..' TB1.PropeTy 9 = "sdfsd" 'tb1.addnew ()' --- Fill-- -'tb1.fill () '' --- delete --- 'tb1.delete ()' '--- Update ---' tb1.fill () 'tb1.propety1 = "sdfsd" only Update ProPeety11 Value 'tb1.update () ----------------------------------------- -----------------

Class TB_TABLENAME '[MODIFY] Classification Change to Table Related Name Private P_dbConnection, P_DBConnstring' Connect Database Variable PRIVATE P_RS, P_TABLENAME 'Recording Set, Data Table Name Variable PRIVATE P_ERROR, P_ERRORDESC (14)' Error Information

'----- The variable below is the field private p_property1, p_property2, p_property3, p_property2 private p_property3, p_property4 private p_property5, p_property6, p_property7, p_property8, p_property9

'=============== System process ========================== ---------- -------- Class initialization ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ] If there is no application () variable direct input link string p_tablename = "tablename" '[modify] change to data table name p_ERROR = 0' This value is used to return the error message 0 No error 1-. . . The following correspondence error P_ERRRORDESC (1) = "Unknown error!" P_errordesc (2) = "database link is unsuccessful!" P_errordesc (3) = "database closes unsuccessful!" P_ERRORDESC (4) = "New record process is unsuccessful!" "P_ERRORDESC (5) =" did not find the specified data, unable to update the data! "P_ERRORDESC (6) =" Delete data is unsuccessful! "P_errordesc (7) =" "p_errordesc (8) =" Read record set is unsuccessful! " P_ERRORDESC (9) = "Did not find records to update!" P_ERRORDESC (10) = "update record is unsuccessful!" p_errordesc (11) = "P_lerdesc (12) =" did not find the specified data, Unable to fill the data! "P_errordesc (13) =" "" p_errordesc (14) = "" "'p_property = inivalue

End Sub

'-------------- Class destruction ------------------ Private sub class_terminate on error resume next

IF isobject (p_dbconnection) THEN 'destroyed database link object p_dbconnection.close set p_dbconnection = nothing end ifif isobject (p_rs) Then' destroying RecordSet object p_rs.close set p_rs = nothing endiff

End Sub

'=============================== ---------- Property: Return to the version number to the user - only Read ------------------- Public Property Get Version Version = "DB Table Templete Class Version (1.0)" Version = Version & "
Made by Scott! Hbzhuxu @ 21cn.com "End Property

'---------- Property: Error code Returns the error code to the user - read-only -------- Public property get error = p_ERROR END Property

'--------- Property: Error message Returns Error Description to User - Read-only --------- Public Property Get ErrorDesc on Error ResMe next if not isnumeric (p_ERROR) THEN P_ERROR = 1 IF P_ERROR = 0 Then ErrorDesc = "There is no error!" Else ErrorDesc = p_ERRRORDESC (P_ERROR) IF Err.Number> 0 Then ErrorDesc = ErrorDesc & Err.description End If End Property

'================ functional attribute ================================================================================================= -------------- Property: DBConnstring DB Connection String ---------- Public Property Get dbconnstring dbconnstring = p_dbconnstring End Property

Public property let dbconnstring (Strvalue) p_dbconnstring = Strvalue End Property

'============== This is the get let ============================================================================================================================================= ------- Field Properties: Property1 ------------------ Public Property Get Property1 PROPERTY1 = P_Property1 End PropertyPublic Property Let Property1 (strValue) P_Property1 = Strvalue End Property

'-------------- Field Properties: Property2 ------------------ Public property get prot = = p_property2 End Property

Public Property Let Property2 (strValue) p_property2 = STRVALUE End Property

'-------------- Field Properties: Property3 ------------------ Public Property Get Property3 Property3 = P_Property3 End Property

Public Property Let Property3 (Strodue) P_Property3 = Strvalue End Property

'-------------- Field Properties: Property4 ------------------ Public Property Get Property4 Property4 = P_Property4 End Property

Public property Let Property4 (strValue) p_property4 = Strvalue End Property

'-------------- Field Properties: Property5 ------------------ Public Property Get Property5 Property5 = P_Property5 End Property

Public Property Let Property5 (strValue) p_property5 = STRVALUE End Property

'-------------- Field Properties: Property6 ------------------ Public Property Get Property6 Property6 = P_Property6 End Property

Public Property Let Property6 (strValue) p_property6 = STRVALUE End Property

'-------------- Field Properties: Property7 ------------------ Public Property Get Property7 Property7 = P_Property7 End Property

Public Property Let Property7 (Strodue) P_Property7 = Strvalue End Property

'-------------- Field Properties: Property8 ------------------ Public Property Get Property8 Property8 = P_Property8 End PropertyPublic Property Let Property8 ( Strvalue) p_property8 = STRVALUE End Property

'-------------- Field Properties: Property9 ------------------ Public Property Get Property9 Property9 = P_Property9 End Property

Public Property Let Property9 (Strodue) P_Property9 = Strvalue End Property

'================= class procedure and method =================== -------------- - Open the database ---------- "If there is already a connection, use it directly, do you create a connection '' parameter: global variable conn and global variable dbconnstring 'Return: Connection correct attribute error correctly Return 0, error Returns 2 public sub dbopen () on error resume next set p_dbconnection = server.createObject ("adodb.connection") if isobject (conn) fen "If there is a global CONN, use existing connections, exit and return 1 set p_dbconnection = conn EXIT SUB END IF 'Otherwise, created and open new link p_dbconnection.open p_dbconnstring if err.number> 0 THEN P_ERROR = 2 end if End sub' ---------- Close Database -------- ----- If the connection is turned on, close it '' parameters: 'Return: Connect to close the property error correctly close 20, error Return 2 Public Sub dbclose () on error resume next if isobject (p_dbconnection) Then' If connection Presence, close p_dbconnection.close set p_dbconnection = NothUMBER> 0 THEN P_ERROR = 3 End if End Sub '----------- Add a record to the database ----- ------ 'Inserting records with add new statement directly writes the attribute value to DB / needs to open the database connection' This syntax security is better than INSERT, the performance is slightly poor '' parameter: private variable 'Return: Processing correctly returned 1 , Error Back 0 public sub addnew () on error resume next strsql = "select * from" & p_tablename & "Where 1 = 2; "SET RS = Server.createObject (" AdoDb.Recordset ") RS.Open Strsql, p_dbconnection, 3,3 rs.addnew = p_property1 rs (" Property2 ") = p_property2 RS (" Property3 ") = P_property3 RS (" Property4 ") = p_property4 rs (" Property5 ") = p_property5 rs (" Property6 ") =

p_Property6 rs ( "Property7") = p_Property7 rs ( "Property8") = p_Property8 rs ( "Property9") = p_Property9 rs.Update rs.close set rs = nothing If err.number> 0 Then p_Error = 4 End If End Sub ' ----------- Remove the record from the database ---------- 'Delete records with DELETE statement / need to open the database connection' 'parameter: private variable' Return: Processing correctly returned 1 , error return 0 Public Function Delete () On error Resume Next strSql = "delete * from" & p_TableName & "Property1 =" & p_Property1 p_DbConnection.execute strsql If err.number> 0 Then p_Error = 6 End If End Function '- --------- to update records to the database --------- 'Update record / needs to open the database connection with UPDATE statement "parameter: private variable' Return: Processing correctly returned 1, error return 0 Public Function Update () On Error Resume Next strSql = "select * from" & p_TableName & "Property1 =" & p_Property1 set rs = Server.CreateObject ( "ADODB.Recordset") rs.open strSql, p_DbConnection, 3,3 If not (rs.bof and eeof) Then if len (p_property2)> 0 THEN RS ("Property2") = p_property2 End if if len (p_property3)> 0 THEN RS ("Property3" = p_property3 end ififf (p_property4)> 0 THEN RS ("PR Operty4 ") = p_property4 end if if len (p_property5)> 0 THEN RS (" Property5 ") = p_property5 end if if len (p_property6)> 0 THEN RS (" Property6) = p_property6 end ifness = p_property6 End ifness THEN RS ("Property7") = p_property7 end if if let (p_property8)> 0 THEN RS ("Property8") = p_property8 end if if len (p_property9)> 0 THEN RS ("Property9) =

p_property9 end if rupdate else p_ERROR = 9 end if if err.number> 0 THEN P_ERROR = 10 End if = = nothing end function '----------- From the database taken a new Record ---------- 'Use SELECT Starts Record / Need to Open Database Connection' 'Parameters: Private Variable' Returns: Processing Correct Back 1, Error Back 0 Public Function Fill () ON Error ResMe Next Strsql = "SELECT *" & P_TABLENAME & "Property1 =" & p_property1 set = server.createObject ("adoDb.recordset") RS.Open strsql, p_dbconnection, 0,1 if not (rs.bof and re) THEN p_Property1 = rs ( "Property1") p_Property2 = rs ( "Property2") p_Property3 = rs ( "Property3") p_Property4 = rs ( "Property4") p_Property5 = rs ( "Property5") p_Property6 = rs ( "Property6") p_Property7 = RS ("Property7") p_property8 = rs ("Property8") p_property9 = rs ("Property9") ELSE P_ERROR = 12 end if if Err.Number> 0 THEN P_ERROR = 11 end if rs.close set = Nothing end function ' ----------- From the database take a new record --------- 'Use the SELECT Starting Record / Need to turn on the Database Connection' 'parameter: private Variable' Return: Processing correct Return 1. Error Return 0 public function list ) On Error Resume Next strSql = "select * from" & p_TableName & "Property1 =" & p_Property1 set rs = Server.CreateObject ( "ADODB.Recordset") rs.open strSql, p_DbConnection, 0,1 If not (rs.bof And aProperty1 = RS ("Property1") P_Property2 = RS ("Property2") P_Property3 = RS ("Property3") P_Property4 = RS ("Property4") P_Property5 = RS ("Property5"

P_Property6 = RS ("Property6") P_Property7 = RS ("Property7") P_Property8 = RS ("Property8") P_Property9 = RS ("Property9") Else P_ERROR = 12 End if if Err.Number> 0 THEN P_ERROR = 11 END IF = Nothing end functionend class%>

<% '----------------------------------------------- ------------------------- '********************** *** Database - Table - Module Class 2.0 ********************************************************** *********************************************************** ******************** The private variable: p_dbconnection: database link, p_tablename: Table name 'attribute: dbconnstring: Database linked string' error: Error code errordesc : Error message Version: Version information 'Property1: Field 1 Property2: Field 2 Property3: Field 3' Property4: Field 4 Property5: Field 5 Property6: Field 6 'Property7: Field 7 Property8: Field 8 Property9: Field 9' method: ' DBOPEN () 'dbclose ()' INSERT () Directly add information stored in the properties field to the database 'addnew () directly stores information stored in the properties field to the database in the database' delete () DELETE statement delete record / needs to open database connection parameters: SQL WHERE clause 'update () Use Update statement update record / needs to open Database connection parameters: SQL WHERE clause' Fill () Take 1 record / need to open Databases with SELECT Connection parameters: SQL WHERE clause '' Usage: '1 Copy this mode to new file, filename changes' 2 changes by the table name' 3 Change Property "3 Change Property to the corresponding field in the table (with Replace, Directly replaced Property1, do not select WHOLE WORD INLY '4 Adjusting the get and let'5 of each field to handle error code' '--------------- Application example - ------- 'set tb1 = new TB_TABLENAME' Instantian 'TB1.DBOPEN' Open DB '' --- addNew --- 'tb1.propety 1 = "SDFSD"' to the attribute assignment '..' TB1.PropeTy 9 = "sdfsd" 'tb1.addnew ()' --- Fill-- -'tb1.fill () '' --- delete --- 'tb1.delete ()' '--- Update ---' tb1.fill () 'tb1.propety1 = "sdfsd" only Update ProPeety11 Value 'tb1.update () ----------------------------------------- -----------------

Class TB_TABLENAME '[MODIFY] Classification Change to Table Related Name Private P_dbConnection, P_DBConnstring' Connect Database Variable PRIVATE P_RS, P_TABLENAME 'Recording Set, Data Table Name Variable PRIVATE P_ERROR, P_ERRORDESC (14)' Error Information

'----- The variable below is the field private p_property1, p_property2, p_property3, p_property2 private p_property3, p_property4 private p_property5, p_property6, p_property7, p_property8, p_property9

'=============== System process ========================== ---------- -------- Class initialization ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ] If there is no application () variable direct input link string p_tablename = "tablename" '[modify] change to data table name p_ERROR = 0' This value is used to return the error message 0 No error 1-. . . The following correspondence error P_ERRRORDESC (1) = "Unknown error!" P_errordesc (2) = "database link is unsuccessful!" P_errordesc (3) = "database closes unsuccessful!" P_ERRORDESC (4) = "New record process is unsuccessful!" "P_ERRORDESC (5) =" did not find the specified data, unable to update the data! "P_ERRORDESC (6) =" Delete data is unsuccessful! "P_errordesc (7) =" "p_errordesc (8) =" Read record set is unsuccessful! " P_ERRORDESC (9) = "Did not find records to update!" P_ERRORDESC (10) = "update record is unsuccessful!" p_errordesc (11) = "P_lerdesc (12) =" did not find the specified data, Unable to fill the data! "P_errordesc (13) =" "" p_errordesc (14) = "" "'p_property = inivalue

End Sub

'-------------- Class destruction ------------------ Private sub class_terminate on error resume next

IF isobject (p_dbconnection) THEN 'destroyed database link object p_dbconnection.close set p_dbconnection = nothing end ifif isobject (p_rs) Then' destroying RecordSet object p_rs.close set p_rs = nothing endiff

End Sub

'=============================== ---------- Property: Return to the version number to the user - only Read ------------------- Public Property Get Version Version = "DB Table Templete Class Version (1.0)" Version = Version & "
Made by Scott! Hbzhuxu @ 21cn.com "End Property

'---------- Property: Error code Returns the error code to the user - read-only -------- Public property get error = p_ERROR END Property

'--------- Property: Error message Returns Error Description to User - Read-only --------- Public Property Get ErrorDesc on Error ResMe next if not isnumeric (p_ERROR) THEN P_ERROR = 1 IF P_ERROR = 0 Then ErrorDesc = "There is no error!" Else ErrorDesc = p_ERRRORDESC (P_ERROR) IF Err.Number> 0 Then ErrorDesc = ErrorDesc & Err.description End If End Property

'================ functional attribute ================================================================================================= -------------- Property: DBConnstring DB Connection String ---------- Public Property Get dbconnstring dbconnstring = p_dbconnstring End Property

Public property let dbconnstring (Strvalue) p_dbconnstring = Strvalue End Property

'============== This is the get let ============================================================================================================================================= ------- Field Properties: Property1 ------------------ Public Property Get Property1 PROPERTY1 = P_Property1 End PropertyPublic Property Let Property1 (strValue) P_Property1 = Strvalue End Property

'-------------- Field Properties: Property2 ------------------ Public property get prot = = p_property2 End Property

Public Property Let Property2 (strValue) p_property2 = STRVALUE End Property

'-------------- Field Properties: Property3 ------------------ Public Property Get Property3 Property3 = P_Property3 End Property

Public Property Let Property3 (Strodue) P_Property3 = Strvalue End Property

'-------------- Field Properties: Property4 ------------------ Public Property Get Property4 Property4 = P_Property4 End Property

Public property Let Property4 (strValue) p_property4 = Strvalue End Property

'-------------- Field Properties: Property5 ------------------ Public Property Get Property5 Property5 = P_Property5 End Property

Public Property Let Property5 (strValue) p_property5 = STRVALUE End Property

'-------------- Field Properties: Property6 ------------------ Public Property Get Property6 Property6 = P_Property6 End Property

Public Property Let Property6 (strValue) p_property6 = STRVALUE End Property

'-------------- Field Properties: Property7 ------------------ Public Property Get Property7 Property7 = P_Property7 End Property

Public Property Let Property7 (Strodue) P_Property7 = Strvalue End Property

'-------------- Field Properties: Property8 ------------------ Public Property Get Property8 Property8 = P_Property8 End PropertyPublic Property Let Property8 ( Strvalue) p_property8 = STRVALUE End Property

'-------------- Field Properties: Property9 ------------------ Public Property Get Property9 Property9 = P_Property9 End Property

Public Property Let Property9 (Strodue) P_Property9 = Strvalue End Property

'================= class procedure and method =================== -------------- - Open the database ---------- "If there is already a connection, use it directly, do you create a connection '' parameter: global variable conn and global variable dbconnstring 'Return: Connection correct attribute error correctly Return 0, error Returns 2 public sub dbopen () on error resume next set p_dbconnection = server.createObject ("adodb.connection") if isobject (conn) fen "If there is a global CONN, use existing connections, exit and return 1 set p_dbconnection = conn EXIT SUB END IF 'Otherwise, created and open new link p_dbconnection.open p_dbconnstring if err.number> 0 THEN P_ERROR = 2 end if End sub' ---------- Close Database -------- ----- If the connection is turned on, close it '' parameters: 'Return: Connect to close the property error correctly close 20, error Return 2 Public Sub dbclose () on error resume next if isobject (p_dbconnection) Then' If connection Presence, close p_dbconnection.close set p_dbconnection = NothUMBER> 0 THEN P_ERROR = 3 End if End Sub '----------- Add a record to the database ----- ------ 'Inserting records with add new statement directly writes the attribute value to DB / needs to open the database connection' This syntax security is better than INSERT, the performance is slightly poor '' parameter: private variable 'Return: Processing correctly returned 1 , Error Back 0 public sub addnew () on error resume next strsql = "select * from" & p_tablename & "Where 1 = 2; "SET RS = Server.createObject (" AdoDb.Recordset ") RS.Open Strsql, p_dbconnection, 3,3 rs.addnew = p_property1 rs (" Property2 ") = p_property2 RS (" Property3 ") = P_property3 RS (" Property4 ") = p_property4 rs (" Property5 ") = p_property5 rs (" Property6 ") =

p_Property6 rs ( "Property7") = p_Property7 rs ( "Property8") = p_Property8 rs ( "Property9") = p_Property9 rs.Update rs.close set rs = nothing If err.number> 0 Then p_Error = 4 End If End Sub ' ----------- Remove the record from the database ---------- 'Delete records with DELETE statement / need to open the database connection' 'parameter: private variable' Return: Processing correctly returned 1 , error return 0 Public Function Delete () On error Resume Next strSql = "delete * from" & p_TableName & "Property1 =" & p_Property1 p_DbConnection.execute strsql If err.number> 0 Then p_Error = 6 End If End Function '- --------- to update records to the database --------- 'Update record / needs to open the database connection with UPDATE statement "parameter: private variable' Return: Processing correctly returned 1, error return 0 Public Function Update () On Error Resume Next strSql = "select * from" & p_TableName & "Property1 =" & p_Property1 set rs = Server.CreateObject ( "ADODB.Recordset") rs.open strSql, p_DbConnection, 3,3 If not (rs.bof and eeof) Then if len (p_property2)> 0 THEN RS ("Property2") = p_property2 End if if len (p_property3)> 0 THEN RS ("Property3" = p_property3 end ififf (p_property4)> 0 THEN RS ("PR Operty4 ") = p_property4 end if if len (p_property5)> 0 THEN RS (" Property5 ") = p_property5 end if if len (p_property6)> 0 THEN RS (" Property6) = p_property6 end ifness = p_property6 End ifness THEN RS ("Property7") = p_property7 end if if let (p_property8)> 0 THEN RS ("Property8") = p_property8 end if if len (p_property9)> 0 THEN RS ("Property9) =

p_property9 end if rupdate else p_ERROR = 9 end if if err.number> 0 THEN P_ERROR = 10 End if = = nothing end function '----------- From the database taken a new Record ---------- 'Use SELECT Starts Record / Need to Open Database Connection' 'Parameters: Private Variable' Returns: Processing Correct Back 1, Error Back 0 Public Function Fill () ON Error ResMe Next Strsql = "SELECT *" & P_TABLENAME & "Property1 =" & p_property1 set = server.createObject ("adoDb.recordset") RS.Open strsql, p_dbconnection, 0,1 if not (rs.bof and re) THEN p_Property1 = rs ( "Property1") p_Property2 = rs ( "Property2") p_Property3 = rs ( "Property3") p_Property4 = rs ( "Property4") p_Property5 = rs ( "Property5") p_Property6 = rs ( "Property6") p_Property7 = RS ("Property7") p_property8 = rs ("Property8") p_property9 = rs ("Property9") ELSE P_ERROR = 12 end if if Err.Number> 0 THEN P_ERROR = 11 end if rs.close set = Nothing end function ' ----------- From the database take a new record --------- 'Use the SELECT Starting Record / Need to turn on the Database Connection' 'parameter: private Variable' Return: Processing correct Return 1. Error Return 0 public function list ) On Error Resume Next strSql = "select * from" & p_TableName & "Property1 =" & p_Property1 set rs = Server.CreateObject ( "ADODB.Recordset") rs.open strSql, p_DbConnection, 0,1 If not (rs.bof And aProperty1 = RS ("Property1") P_Property2 = RS ("Property2") P_Property3 = RS ("Property3") P_Property4 = RS ("Property4") P_Property5 = RS ("Property5"

转载请注明原文地址:https://www.9cbs.com/read-50101.html

New Post(0)