The student information management system has been completed and the first acceptance is also carried out. The results are not very satisfactory. The previous summary was not published in time. Review it again and post it. From today on, we have entered the code analysis phase. Now let's analyze several functions in the module. PublicFunctionExecuteSQL (ByValSQLAsStr
The student information management system has been completed and the first acceptance is also carried out. The results are not very satisfactory. The previous summary was not published in time. Review it again and post it. From today on, we have entered the code analysis phase. Now let's analyze several functions in the module. Public Function ExecuteSQL (ByVal SQL As Str
The student information management system has been completed and the first acceptance is also carried out. The results are not very satisfactory. The previous summary was not published in time. Review it again and post it.
From today on, we have entered the code analysis phase. Now let's analyze several functions in the module.
Public Function ExecuteSQL (ByVal SQL As String, MsgString As String) As ADODB. recordset 'executes SQL and returns Recordset Dim cnn As ADODB. connection Dim rst As ADODB. recordset Dim metrics ENS () As String On Error GoTo ExecuteSQL_Error metrics ENS = Split (SQL) Set cnn = New ADODB. connection cnn. open ConnectString If InStr ("INSERT, DELETE, UPDATE", UCase $ (ENS (0) then' non-Select statement cnn. execute SQL 'When the data volume is small, you can directly Execute the SQL statement MsgString = ENS (0) & "query successful" 'on the connection. although MsgString is not the return value, the passing method is ByRef, the real parameter address is the same as the address Else 'Select statement Set rst = New ADODB. recordset rst. open Trim $ (SQL), cnn, adOpenKeyset, adLockOptimistic 'to get a temporary table. the cursor points to the first record 'get RecordCount, Set ExecuteSQL = rst MsgString = "" & rst. recordCount & _ "record" End If ExecuteSQL_Exit: Set rst = Nothing Set cnn = Nothing Exit Function ExecuteSQL_Error: MsgString = "query error:" & _ Err. description Resume ExecuteSQL_ExitEnd Function
ExecuteSQL functions:
Description: query a string using an SQL statement and return an ADO record set.
1. split () function
Explanation: vt. split; separate
Computer language explanation: returns a one-dimensional array with a subscript starting from scratch. it contains a specified number of substrings.
Syntax: Split (expression [, delimiter [, count [, compare])
Personal Understanding: split (SQL) refers to splitting the entire SQL statement into an array.
For example:
SQL = "select * from user_Info"
Split (SQL)
STokens (0) = select
STokens (1) = *
STokens (2) = from
STokens (3) = user_Info
In this way, a complete SQL statement is split into an array.
2. Instr () function
Meaning: string processing function. it returns the position of the string to be truncated in the source string.
Syntax: Instr ([start,] string1, string2 [, compare])
Start from the Start position (if omitted from the first place), find string2 in string1, and return 0 if not found.
For example:
If SQL = "select * from user_Info"
Then InStr ("INSERT, DELETE, UPDATE", UCase $ (sTokens (0) = 0