Function 传递函数参数vbscript时出现问题

Function 传递函数参数vbscript时出现问题,function,vbscript,resultset,Function,Vbscript,Resultset,我对vbscript有点问题 我已经声明了一些函数,它像参数一样传递sql查询的结果集,问题是函数showData像对象一样接受参数,而不像resultset function get_count(conn) dim query, size Set query = Server.CreateObject("ADODB.Recordset") set query = conn.Execute("select count(*) as size from doctor")

我对vbscript有点问题 我已经声明了一些函数,它像参数一样传递sql查询的结果集,问题是函数showData像对象一样接受参数,而不像resultset

function get_count(conn)
    dim query, size
    Set query = Server.CreateObject("ADODB.Recordset")
    set query = conn.Execute("select count(*) as size from doctor")
    size = query.Fields("size")
    get_count = size
end function
function get_rows_from_to(from,size,conn)
    dim result
    Set result = Server.CreateObject("ADODB.Recordset")
    set result = conn.Execute("SELECT name, surname,family,egn,citizenship FROM doctor limit "&from&","&size&"")
    get_rows_from_to = result
end function
Sub showData(objRS)
    dim isEven
    isEven = false
    Response.Write "<table>"
    Response.Write "<tr>"
    Response.Write "<th >Име</th><th >Презиме</th><th >Фамилия</th><th >ЕГН</th><th >Гражданство</td>"
    Response.Write "</tr>"
    While Not objRS.EOF
        Response.Write "<tr>"
        if isEven then
            Response.Write "<td style = 'background-color :#e9ebf2'>"&objRS.Fields("name")&"</td>"&_
                "<td style = 'background-color :#e9ebf2'>"&objRS.Fields("surname")&"</td>"&_
                "<td style = 'background-color :#e9ebf2'>"&objRS.Fields("family")&"</td>"&_
                "<td style = 'background-color :#e9ebf2'>"&objRS.Fields("egn")&"</td>"&_
                "<td style = 'background-color :#e9ebf2'>"&objRS.Fields("citizenship")&"</td>"
            isEven = false
        else
            Response.Write "<td>"&objRS.Fields("name")&"</td><td>"&objRS.Fields("surname")&"</td><td>"&objRS.Fields("family")&"</td><td>"&objRS.Fields("egn")&"</td><td>"&objRS.Fields("citizenship")&"</td>"
            isEven = true
        end if
        Response.Write "</tr>"
        objRS.MoveNext
    Wend 
    Response.Write "</table>"
    objRS.Close
end sub
const ROWS_PER_PAGE = 10
Dim sConnection, conn , result,pages,selPage,from,lenght,pos,size

from = 0
lenght = 10
pos = 1
size = 0
sConnection = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=localhost; DATABASE=docunion; UID=root;PASSWORD=root; OPTION=3" 

Set conn = Server.CreateObject("ADODB.Connection") 
Set result = Server.CreateObject("ADODB.Recordset")
conn.Open sConnection

size = get_count (conn)
size = CInt(size)
if size  > 0 then
    pages = size / 10
    lenght = (ROWS_PER_PAGE*pos)
    set result = get_rows_from_to(from,lenght,conn)
    from = lenght + 1
    pos = pos + 1
    showData(result)
else
    Set result = Nothing
    conn.Close
    Set conn = Nothing
end if

主要问题是,返回对象引用的函数必须使用
Set
作为其返回值:

函数获取从到的行(从、大小、连接)
' ...
将get\u rows\u from\u设置为=结果
端函数
其他一些提示:

在使用函数之前,不需要声明它们。您可以将所有函数声明放在脚本的末尾,并将主脚本体保持在顶部

这是多余的:

函数获取从到的行(从、大小、连接)
模糊结果
Set result=Server.CreateObject(“ADODB.Recordset”)
set result=conn.Execute(“选择姓名、姓氏、家庭、egn、来自医生限制的公民身份”&来自&“,”大小&“)
将get\u rows\u from\u设置为=结果
端函数
相当于这个

函数获取从到的行(从、大小、连接)
将get_rows_from_设置为=conn.Execute(“从医生限制中选择姓名、姓氏、家庭、egn、公民身份”&from&“,&size&”)
端函数
conn.Execute()
已返回ADODB.RecordSet。以前通过
Server.CreateObject()
创建一个空白对象是没有意义的。事实上,所有的
Set xyz=Server.CreateObject(“ADODB.Recordset”)
行都是多余的

为函数中的返回值创建单独的变量没有意义。函数是其返回值:

函数getFoo() getFoo=“foo” 端函数 最后两个提示:

  • 始终使用
    选项Explicit
  • 始终对输出到页面的任何数据段使用
    Server.HtmlEncode()
    。这比所有其他提示都更重要

主要问题是,返回对象引用的函数必须使用
Set
作为其返回值:

函数获取从到的行(从、大小、连接)
' ...
将get\u rows\u from\u设置为=结果
端函数
其他一些提示:

在使用函数之前,不需要声明它们。您可以将所有函数声明放在脚本的末尾,并将主脚本体保持在顶部

这是多余的:

函数获取从到的行(从、大小、连接)
模糊结果
Set result=Server.CreateObject(“ADODB.Recordset”)
set result=conn.Execute(“选择姓名、姓氏、家庭、egn、来自医生限制的公民身份”&来自&“,”大小&“)
将get\u rows\u from\u设置为=结果
端函数
相当于这个

函数获取从到的行(从、大小、连接)
将get_rows_from_设置为=conn.Execute(“从医生限制中选择姓名、姓氏、家庭、egn、公民身份”&from&“,&size&”)
端函数
conn.Execute()
已返回ADODB.RecordSet。以前通过
Server.CreateObject()
创建一个空白对象是没有意义的。事实上,所有的
Set xyz=Server.CreateObject(“ADODB.Recordset”)
行都是多余的

为函数中的返回值创建单独的变量没有意义。函数是其返回值:

函数getFoo() getFoo=“foo” 端函数 最后两个提示:

  • 始终使用
    选项Explicit
  • 始终对输出到页面的任何数据段使用
    Server.HtmlEncode()
    。这比所有其他提示都更重要

使用
Set
的提示是一个救命稻草+1使用
Set
的提示是一个救命稻草+1.
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'EOF'
/index.asp, line 57