The meaning of each code of the Executssql function

Source: Internet
Author: User

  1. Public Function ExecuteSQL (ByVal sql As String, msgstring as String) as ADODB. Recordset
  2. Dim CNN as ADODB. Connection ' defines the connection form of CNN for a database, and the function to connect and open the database cnnectstring with the cnnectstring () function is described below
  3. Dim rst as ADODB. Recordset ' defines a temporary list of data that is taken from the database
  4. Dim Stokens () as String defines an array that stores SQL statements as arrays
  5. On Error GoTo Executesql_error ' If an error occurs, the emergency handling
  6. Okens = Split (SQL) uses the Split function to deposit the SQL statement into an array by word, for example: if the SQL statement is a SELECT * from student, then the result of the run is--sto Kens (0) = "Select", stokents (1) = "*", stokens (2) = "from", Stokens (3) = "Student"
  7. Set cnn = New ADODB. Connection ' to instantiate CNN
  8. Cnn. Open connectstring ' connects the database via ConnectString and opens
  9. If InStr ("Insert,delet,update", ucase$ (Stokens (0))) Then ' determines whether the query operation is done through the SELECT statement
  10. Cnn. Execute Sql<span style= "White-space:pre" > </span> "performs the operation without returning the result of the operation.
  11. msgstring = Stokens (0) & "Query Successful"
  12. Else
  13. Set rst = New ADODB. Instantiation of the Recordset ' temp list
  14. Rst. Open trim$ (SQL), CNN, adOpenKeyset, adLockOptimistic ' rst opening,trim& () is the action string to be held; CNN is a string expression, the name of the ODBC data source that is logged in, open in a way 。 ; Dopenkeyset, determines the type of cursor (that is, how to find) to use keyset cursors. You cannot access records deleted by another user, but it is similar to dynamic cursors except that you cannot view records added by other users. Data changes made by other users are still visible; adLockOptimistic, when the data source is being updated, the system does not lock other users ' actions, and other users can add, delete, and change the data.
  15. Set ExecuteSQL = RST ' assigns the resulting temporary list to the ExecuteSQL function, especially it returns and assigns it further to the MRC
  16. msgstring = "Query to" & rst. RecordCount & "Records"
  17. End If
  18. Utesql_exit: ' An operation to empty the temporary list before the function exits.
  19. Set rst = Nothing
  20. Set cnn = Nothing
  21. Exit Function
  22. Utesql_error: ' Error ID, handling when error occurs
  23. msgstring = "Query Error:" & _
  24. Err.Description
  25. Resume Executesql_exit
  26. Function


The introduction of the ConnectString () function

The meaning of each code of the Executssql function

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.