Use WSH to query the database like ASP! (WSH learning experience 2)

Source: Internet
Author: User
Tags constant object model
WSH is a Windows Script hosting file.
You can write WSH scripts in both VBScript and JScript.
Be aware that although IE browsers and WSH use the same language
Engines, but they do not support the same object model. For example, WSH does not support Window.document objects for user output.
WSH Environment does not provide an extended user interface (as in IE browser), WSH object model does not expose the user interface
Events (such as Onlick events in HTML scripts), the event-handling mechanisms provided by IE browsers are not useful in WSH environments.
However, WSH also supports event handling.
Here are two of the simplest WSH scripts Hello.vbs and Hello.js
'------------
' Hello.vbs
WScript.Echo "Hello,word"
'------------
//-----------
Hello.js
WScript.Echo ("Hello,word");
Special attention to write with JS, when the case sensitive. such as: WScript written WScript will be an error!
//-----------
WSH can use ActiveX components, such as ADO, File Access objects, or CDO for NTS, but WSH
You cannot use any of the built-in ative Server Page objects, such as appliation, session, or request objects.
The following script search.vbs query SQL Server with ADO:
'-------
' Search.vbs
Set conn = WScript. CreateObject ("ADODB.") Connection ")
Conn. Open "driver={sql server};server=000.000.00.00;uid=you;pwd=your password;" & "Database=yourdata;"
Set RS = Conn.execute ("SELECT * from yourtable ORDER BY id DESC")
For i = 0 to RS. Fields.count-1
WScript.Echo RS (i). Name
Next
While not RS. Eof
For i = 0 to RS. Fields.count-1
WScript.Echo RS (i). Value
Next
Rs. MoveNext
Wend
'-------
In addition to using WScript. CreateObject rather than using the server. CreateObject to create
Activex object instance, using WScript.Echo instead of using Response.Write to present output
, this script is exactly the same as the ASP script. One limitation in WSH version 1, known as the Windows scripting Host, is that no other files are included in the WSH script, and there is no instruction equivalent to #include in the ASP. One of the consequences of this limitation is the inability to include the ADO constant file (Adovbs.inc) in the WSH script. To use an ADO constant, you must copy the contents of the change file into the WSH file or in the script
The source value of the constant used in the Neither approach is very good.
The good news is that Microsoft can always find a solution, in WSH version 2 (called Windows Script Host), in addition to the use of. vbs and. js
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.