Isaac K Antwi Isaac K Antwi - 26 days ago 8
Vb.net Question

Convert csharp code to VB

I am trying to read an XML into textbox in VB.

Tried all I could but not getting any result

Kindly assist me convert this Csharp code to VB

doc = new XmlDocument();
doc.Load(PATH);
root = doc.DocumentElement;
txtName.Text = root.GetElementsByTagName("Name")[0].InnerText;
txtAge.Text = root.GetElementsByTagName("Age")[0].InnerText;
txtAddress.Text = root.GetElementsByTagName("Address")[0].InnerText;


This was my try

doc = New XmlDocument()
doc.Load(PATH)
root = doc.DocumentElement
txtPatientID.Text = root.GetElementsByTagName("Name").ItemOf(0)


but was getting error that "Can not convert to string"

Answer

You missed inner text property at the end

txtPatientID.Text = root.GetElementsByTagName("Name").ItemOf(0).InnerText

Full code:

doc = New XmlDocument()
doc.Load(PATH)
root = doc.DocumentElement
txtName.Text = root.GetElementsByTagName("Name")(0).InnerText
txtAge.Text = root.GetElementsByTagName("Age")(0).InnerText
txtAddress.Text = root.GetElementsByTagName("Address")(0).InnerText