Isaac K Antwi Isaac K Antwi - 7 months ago 50 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();
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()
root = doc.DocumentElement
txtPatientID.Text = root.GetElementsByTagName("Name").ItemOf(0)

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


You missed inner text property at the end

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

Full code:

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