ASP + JavaScript database call Method

Source: Internet
Author: User

<%...
VaR connstr = "" provider = sqloledb; Data Source = localhost; initial catalog = jiaojingdb; user id = sa; Password = 123456 ;"
VaR conn = server. Createobject ("ADODB. Connection"); // The purpose of defining Conn is to improve efficiency and close () later, but the physical connection still exists, resulting in high efficiency.
Conn. Open (connstr );
// ** Call the stored procedure through the connection object **
VaR rs = conn. Execute ("getuserlist",) 'the last parameter is the same as commandtype

// Entity:
While (! Rs. EOF ){
Response. Write ("<br>" + RS ("title ");
Rs. movenext ();
}
// Remember to close ()
Rs. Close ();
Conn. Close ();


// If the deletion is performed: conn. Execute (SQL)
/** Call the stored procedure through the recordset object **
// Var myrst = server. Createobject ("ADODB. recordset ")
// Myrst. Open (getuserlist ", myconstr, 0, 1, 4)
// 'Myconstr is the database connection string. The last parameter has the same meaning as commandtype. The second to the last parameter indicates reading, and the third parameter indicates adding, deleting, and modifying.
*/
/** // * Common attributes and methods in the recordset component include:
Rs. Fields. Count: number of fields in the recordset object.
RS (I). Name: name of the I-th field, where I is 0 to Rs. Fields. Count-1
RS (I): The data of field I, where I is 0 to Rs. Fields. Count-1
RS ("field name"): Specifies the data of a field.
Rs. Record. Count: Total number of data records in the cursor.
Rs. EOF: indicates whether the last record is used.
Rs. movefirst: point to the first record.
Rs. movelast: point to the last record.
Rs. moveprev: point to the previous record.
Rs. movenext: point to the next record.
Rs. getrows: puts data into the array.
Rs. properties. Count: the number of attributes of the resultset or connection of ADO.
Rs. properties (item). Name: name of the resultset or connection of ADO.
Rs. properties: The resultset or connection value of ADO.
Rs. Close (): Close the connection.

Close Database
Conn. Close ()*/

%>
 

There are better solutions for small data sets in vbs:

Let's make Rs. getrows clearer.

Rs. getrows (n): n indicates the number of records retrieved.
Rs. getrows (1): 1 indicates that only one record is returned.
Rs. getrows (-1):-1 indicates the default value. All records are returned.

Use the getrows method to generate a two-dimensional array

If not Rs. EOF then
Dim rsarr
Rsarr = Rs. getrows (-1)
For I = 0 to ubound (rsarr, 2) 'traverse record rows
For J = 0 to ubound (rsarr, 1) 'traverse record Columns
Response. Write rsarr (J, I) 'to obtain the record data in row I + 1 and column J + 1.
Next
Next
End if

Are you clear about the two codes?
Weblogarr = weblog. getrows (log_num) 'to get all data
Ubound (weblogarr, 2) 'to get all rows
Weblogarr (1, pagecount) 'returns the 2nd columns displayed on each page, that is, log_cateid.

Unfortunately, there are no two-dimensional and multi-dimensional arrays in Javascript. I solve this problem through the following methods:

 

<%...
Response. Write ("<SCRIPT arr = new array ();");
VaR arri = 0;
While (! Rs. EOF ){
Response. Write ("arr [" + arri + "] = '" + RS (2) + "';");
Rs. movenext ();
Arri ++;
Response. Write ("</SCRIPT> ");
%>

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.