以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Dot NET,C#,ASP,VB 』  (http://bbs.xml.org.cn/list.asp?boardid=43)
----  在线求救:实时错误91:“对象变量或With块变量未设置”  (http://bbs.xml.org.cn/dispbbs.asp?boardid=43&rootid=&id=10800)


--  作者:zhoufs
--  发布时间:10/7/2004 7:49:00 PM

--  在线求救:实时错误91:“对象变量或With块变量未设置”
使用XML实现客户端与Web服务器的交互,代码如下:
客户端:

Const sURL = "http://localhost/MyApplication/"
Private Sub Command1_Click()
    Dim httpRequest As MSXML.XMLHTTPRequest
    Set httpRequest = New MSXML.XMLHTTPRequest
    
    '构造一个XML格式的字符串
    Dim Company As String, XMLRequest As String
    Company = Text1.Text
    XMLRequest = "<Request>" & "<Company>" & Company & "</Company>" & "</Request>"
    
    '打开一个到Web服务器连接,并发送一个http请求
    httpRequest.open "POST", sURL & "GetCustomer.asp", False
    httpRequest.send XMLRequest
    
    If httpRequest.Status <> 200 Then
      Err.Raise Err.Number, , "Http transport error:" & httpRequest.Status & "Description:" & httpRequest.statusText
    End If
    
    '提取从Web服务器端返回的数据
    Dim ResponseDoc As DOMDocument, LinkMan As String
    Set ResponseDoc = New DOMDocument
    Set ResponseDoc = httpRequest.responseXML
      
    LinkMan = ResponseDoc.selectSingleNode("//LinkMan").Text
    
    Text2.Text = LinkMan
    End Sub

服务器端:(是一个名为GetCustomer.asp的文件)
<%
Response.contentType="text/xml"
set dom=Server.CreateObject("MSXML.DOMDocument")
dom.load Request
Dim Company,LinkMan
Company=dom.selectSingleNode("//Company").text
set conn=server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("Northwind.mdb")
sql = "select 公司名称,联系人姓名 from 客户 where 公司名称 ='" & Company & "'"
rs.Open sql,conn,1
LinkMan=rs("联系人姓名")
rs.close
set conn=nothing
%>
<Response>
  <LinkMan> <% =LinkMan %> </LinkMan>
</Response>


在执行到
LinkMan = ResponseDoc.selectSingleNode("/ nkMan").Text 时出现 
实时错误91:“对象变量或With块变量未设置”
能否帮我找出错误原因


--  作者:doubleG
--  发布时间:10/7/2004 9:23:00 PM

--  
不用ResponseDoc,而用ResponseDoc.documentElement也就是根节点来选择试试。具体情况没看到也不清楚,呵呵
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
235.352ms