Use the GetRows method of the RecordSet object in JS _ Javascript tutorial

Source: Internet
Author: User
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:
  1. ''Code by xujiwei
  2. ''Http://www.xujiwei.cn/
  3. ''Defines Variables
  4. Dim conn, rs, data, recN, I
  5. ''Connect to the database
  6. Set conn = Server. CreateObject ("ADODB. Connection ")
  7. Conn. Open "Provider = Microsoft. Jet. OLEDB.4.0; Data Source = "&_
  8. Server. MapPath ("data. mdb ")
  9. ''
  10. Set rs = conn. Execute ("SELECT id, first, second FROM mytable ")
  11. ''Get the data array
  12. Data = rs. GetRows ()
  13. ''Close the record set and release the object
  14. Rs. Close ()
  15. Set rs = Nothing
  16. ''Get the number of records
  17. RecN = UBound (data, 2)
  18. ''Loop output data
  19. For I = 0 To recN
  20. ''Note: the array subscript starts from 0.
  21. ''Display database data
  22. Response. Write ("ID:" & data (0, I) & ", First:" & data (1, I )&_
  23. ", Second:" & data (2, I )&" ")
  24. Next
  25. ''Close the database connection and release the object
  26. Conn. Close ()
  27. Set conn = Nothing
  28. %>
Related Article

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.