客户端VBScript程序访问数据库 - 不能正常工作

时间:2014-10-06 15:31:09

标签: vbscript

我有以下VBScript客户端代码。它没有按预期工作。第一个错误是 - " MethodDatabase"未识别。我错过了什么 ?我只想显示SQL Server数据库中表T的记录。

<html>
    <head>
        <title> Database Sample Program </title>
        <script type="text/vbscript">
        Sub MethodDatabase()
            Dim connection
            Dim connectionstring
            Dim rs

            Set connection = CreateObject("ADODB.Connection")
            connectionstring = "Provider=SQLOLEDB;Data Source=SQLTEST;Initial Catalog=Sample;Trusted_Connection=Yes"
            connection.Open connectionstring

            Set rs = CreateObject("ADODB.Recordset")
            rs.Open("SELECT * FROM T", connection) ' Table Name Is - "T" With Two Columns - "X" & "Y" 
            rs.MoveFirst

            While Not (rs.eof)
                MsgBox (rs.fields(0) & " - " & rs.fields(1))
                rs.MoveNext
            Wend

            rs.close
            connection.close
        End Sub
        </script>
    </head>

    <body>
        <form name="form1">
            <input type="button" name="button1" value="Click" onClick="MethodDatabase()">
        </form>
    </body>
</html>

1 个答案:

答案 0 :(得分:1)

变化:

rs.Open("SELECT * FROM T", connection)

要:

rs.Open "SELECT * FROM T", connection

在VBScript中,当您调用不返回值的例程时,您don't use parens(除非您使用Call语句)。