views:

54

answers:

1

my code is like this:

        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'"
+1  A: 

You do not need to use Using

Just try

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 

From documentation of using

The using keyword :

As a statement, when it defines a scope at the end of which an object will be disposed.

To check if it has a value compare it to Nothing

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

Try this

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
astander
i know but what if i will not get any value from selectsinglenode..?
Rajesh Rolen- DotNet Developer
actually what i want is that ..if i not get any xmlelement returned from file line then below 2 line should not be executed...and i thinkusing is good option to do this
Rajesh Rolen- DotNet Developer
i know we can use nothing in if statement..but please tell me what will i have to do..if i want to do using here...
Rajesh Rolen- DotNet Developer
To make use of using the object must implement **system.idisposable** which it seems that *XmlElement* does not.
astander
thanks you sir.. its a good solution... i will implement it.. but please explain me if i want to use Using then what i will have to do.. i have to and where i wil have to implement IDisposable interface (according to error)
Rajesh Rolen- DotNet Developer
ok now i got it...thanks lot
Rajesh Rolen- DotNet Developer