2009-12-31 5 views
0

mon code est comme ceci:erreur à l'aide opérande utilisant et XmlElement

 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'" 

Répondre

1

Vous n'avez pas besoin d'utiliser En utilisant

Juste essayer

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 

De la documentation de l'utilisation

Le mot-clé using:

Comme une déclaration, quand il définit une portée à la fin de dont un objet sera disposé.

Pour vérifier si elle a une valeur comparer à Nothing

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

Essayez cette

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 
+0

je sais, mais si je ne vais pas une valeur de selectSingleNode ..? –

+0

en fait ce que je veux est que ..si je ne reçois aucun xmlelement retourné de la ligne de fichier alors en dessous de 2 ligne ne devrait pas être exécutée ... et je pense que est une bonne option pour le faire –

+0

je sais que nous ne pouvons rien utiliser si déclaration ... mais s'il vous plaît dites-moi ce que je dois faire .. si je veux faire en utilisant ici ... –

Questions connexes