| After learning the construction and usage of the SELECT statement, you should learn how to use it. Under the database tool you have mastered, this may mean that you have to press a button that says "execute. On the ASP Webpage, you can immediately execute SQL statements or call them as stored procedures. Once an SQL statement is created, you have to try to access its query results. Obviously, the key here is ASP recordset. When a non-SQL recordset is used, the code for creating a recordset is usually as follows:
Dim objrec
Set objrec = server. Createobject ("ADODB. recordset ")
Objrec. Open "MERs", objconn, 0, 1, 2 If you are familiar with ASP, the above Code is no stranger to you. You should know that "MERs" indicates the name of a data table in the database. Open recordset
To make full use of the SQL skills you are more familiar with, you need to adjust the recordset most commonly used on ASP Web pages:
Dim objrec
Set objrec = server. Createobject ("ADODB. recordset ")
Objrec. Open SQL, objconn, 0, 1, 2 The only modification here is in objrec. open, and then replace the name of the data table to be queried with the variable containing the SQL statement. One of the advantages of this method is that you can specify the cursor type (as shown in the preceding 0, 1, 2 ). Execute SQL
You can use a compact line of code to execute SQL statements to create A recordset. Syntax:
Dim objrec
Set objrec = objconn. Execute (SQL) In the preceding example, the SQL statement you see is the variable where you store your SQL SELECT statement. The code line "runs" an SQL statement (or queries the database), selects the data and stores the data in the recordset. In the preceding example, the variable objrec is used. The main disadvantage of this method is that you cannot select the cursor type you want. On the contrary, recordset always opens with a forward cursor. Because of the cursor, you may be familiar with the two methods for creating recordset. Directly executing a query saves the time required to enter characters, but you have to use the default cursor, in this case, Mao Bo, which often fails to run normally, no matter which method you adopt, the biggest difference between the two is no more than whether the code is refined or not. Without considering what fields you obtain and what your standards are, no matter how much data you store, SQL-based recordset is much smaller in size than the standard recordset opened on ASP, let alone the simplicity of the operation. After all, by filtering data, you eliminate the time-consuming if-then test and the loops that may be used. Write test SQL
Here is a tip. Many professional ASP programmers are used to "writing" their own SQL statements when testing web pages. This can help you debug the code, because you can see the strings passed to the server for execution. What you need to do is to add response. writeyourvariable to display relevant information on the screen. This information should be attached when you submit SQL-related questions to the ASP discussion group. |