0

我的代码是这样的:

        Using StateProv As XmlElement = CType(hotelSearch.SelectSingleNode("/ota:OTA_HotelSearchRQ/ota:Criteria/ota:Criterion/ota:Address/ota:StateProv", nsmgr), XmlElement) 'i am getting error in this line....
        StateProv.SetAttribute("StateCode", BLLHotel_Search.StateCode)
        StateProv.ChildNodes(0).InnerText = BLLHotel_Search.StateName
    End Using

error:
"using operand of type 'System.xml.xmlelement' must implement 'system.idisposable'"
4

1 回答 1

1

您不需要使用Using

你试一试

Dim StateProv As XmlElement = CType(hotelSearch.SelectSingleNode("/ota:OTA_HotelSearchRQ/ota:Criteria/ota:Criterion/ota:Address/ota:StateProv", nsmgr), XmlElement) 'i am getting error in this line.... 
StateProv.SetAttribute("StateCode", BLLHotel_Search.StateCode) 
StateProv.ChildNodes(0).InnerText = BLLHotel_Search.StateName 

从使用文档

使用关键字:

作为一个语句,当它定义一个对象将被释放的范围时。

检查它是否有一个值比较它Nothing

Dim node As XmlNode = doc.SelectSingleNode("//")
If node IsNot Nothing Then
    Dim attribute As XmlAttribute = node.Attributes(0)
End If

试试这个

Dim StateProv As XmlElement = CType(hotelSearch.SelectSingleNode("/ota:OTA_HotelSearchRQ/ota:Criteria/ota:Criterion/ota:Address/ota:StateProv", nsmgr), XmlElement) 

If StateProv IsNot Nothing Then
        StateProv.SetAttribute("StateCode", BLLHotel_Search.StateCode) 
        StateProv.ChildNodes(0).InnerText = BLLHotel_Search.StateName 
End If
于 2009-12-31T07:38:25.307 回答