Analysis of the student information management system (IV) module-mysql tutorial

Source: Internet
Author: User
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

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.