JavaScript: Use the GetRows method of the RecordSet object in JS. Javascript tutorial
When writing an ASP program, VBScript is usually used. However, you can also use JScript instead of this option. However, when JScript is used as the ASP language, it is slightly inconvenient than VBScript, for example, the GetRows method of RecordSet.
RecordSet objects are generally used to operate databases in ASP. If you focus on program efficiency, the GetRows method of the RecordSet object may be used to convert record set objects into arrays, the operation array is much faster than the MoveNext method of the RecordSet object, and the RecordSet object can be released as soon as possible after the array is retrieved, thus reducing resource usage, this is also a method to optimize ASP performance.
In VBScript, a two-dimensional array is obtained using the RecordSet. GetRows method. The data in the array can be obtained by traversing the array.
Assume that there is a database with a table named mytable and three fields named id, first, and second respectively.
Program code:
- ''Code by xujiwei
- ''Http://www.xujiwei.cn/
- ''Defines Variables
- Dim conn, rs, data, recN, I
- ''Connect to the database
- Set conn = Server. CreateObject ("ADODB. Connection ")
- Conn. Open "Provider = Microsoft. Jet. OLEDB.4.0; Data Source = "&_
- Server. MapPath ("data. mdb ")
- ''
- Set rs = conn. Execute ("SELECT id, first, second FROM mytable ")
- ''Get the data array
- Data = rs. GetRows ()
- ''Close the record set and release the object
- Rs. Close ()
- Set rs = Nothing
- ''Get the number of records
- RecN = UBound (data, 2)
- ''Loop output data
- For I = 0 To recN
- ''Note: the array subscript starts from 0.
- ''Display database data
- Response. Write ("ID:" & data (0, I) & ", First:" & data (1, I )&_
- ", Second:" & data (2, I )&" ")
- Next
- ''Close the database connection and release the object
- Conn. Close ()
- Set conn = Nothing
- %>