JS connects SQL Server for querying

Source: Internet
Author: User

<script language= "JavaScript" >//Create database object var objdbconn = new ActiveXObject ("ADODB. Connection ");//DSN string var strdsn =" Driver={sql Server}; server=127.0.0.1; Uid=sa; Pwd=sa;database=coa ";//Open Data source Objdbconn.open (STRDSN);//database query to execute SQL var objRS = objdbconn.execute (" Select Menu_name From Basic_mainmenu ");//Gets the number of fields var Fdcount = objRS. fields.count-1;//Check if there is a record if (!objrs. EOF) {document.write ("<table border=1><tr>");//Display the field name of the database for (var i=0; I <= fdcount; i++) document.write ("<td><b>" + objRS. Fields (i). Name + "</b></td>");d ocument.write ("</tr>");//Display database contents while (!objrs. EOF) {document.write ("<tr>");//show fields for each record for (i=0; I <= fdcount; i++) document.write ("<td valign= ' top ' >" + objRS. Fields (i). Value + "</td>");d ocument.write ("</tr>"); Objrs.movenext (); Move to the next record}document.write ("</table>");} Elsedocument.write ("No record!<br> in database"); objRS. Close (); Close record set Objdbconn.close (); Close database links </script>

http://javamao.iteye.com/blog/625404

JS connects SQL Server for querying

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.