-
August 16th, 2021, 03:25 PM
#1
Find And Change Attribute Value
Hello everyone
I'm fairly new to Visual Basic, so this question might be very "dumb" .
For an assignment I have to read an XML (wines) into a listbox.
From the listbox I then have to select an item and then I have to be able to change the data using. the data from the Textboxes (TBLand, TBName, TBType, TBStreek, TBDruif, TBAlcohol).
Unfortunately this is not going well for me.
I'm trying to search with a query where the information in the textboxes is not the same as the information in the listbox.
If it is unique, I "select" it and then I want to change the value of the Name and Country to the value of the Textboxes and display it in the Listbox.
When I run the program I get a "null" error.
Do you know where I'm going wrong with this?
Code of the Edit button:
Code:
Private Sub ButtonEdit_Click(sender As Object, e As RoutedEventArgs) Handles ButtonWijzig.Click
' De query voor elk attribuut uit het XML dat ongelijk is aan de waarde van de textbox
' Dit element wordt veranderd in de waarde van de textbox
Dim query = From Wijn In xWijnen.Descendants("Wijn")
Where TBLand.Text <> Wijn.Attribute("Land").Value _
And TBNaam.Text <> Wijn.Attribute("Naam").Value _
And TBStreek.Text <> Wijn.Attribute("Streek").Value _
And TBSoort.Text <> Wijn.Attribute("Soort").Value _
And TBDruif.Text <> Wijn.Attribute("Druif").Value _
And TBAlcohol.Text <> Wijn.Attribute("AlcoholPrct").Value
Select WNaam = Wijn.Attribute("Naam").Value,
WLand = Wijn.Attribute("Land").Value
For Each Wijn In query
xWijnen.Element("Naam").SetValue(TBNaam.Text)
xWijnen.Element("Land").SetValue(TBLand.Text)
WijnListBox.Items.Add(xWijnen.Element("Naam").Element("Land").Value)
Next Wijn
Piece of code from the XML file:
Code:
<Wijnen>
<Wijn Naam="Canapi Grillo" Land="Italie" Streek="Sicilie" Soort="Wit" Druif="Grillo" AlcoholPrct="12"/>
<Wijn Naam="Miopasso Fiano" Land="Italie" Streek="Sicilie" Soort="Wit" Druif="Fiano" AlcoholPrct="13"/>
</Wijnen>
-
August 16th, 2021, 03:37 PM
#2
Re: Find And Change Attribute Value
Set a breakpoint in your code and debug it. You be able to see variable values which will help you figure out what is going wrong.
-
September 2nd, 2021, 03:29 AM
#3
Re: Find And Change Attribute Value
This:
Code:
Select WNaam = Wijn.Attribute("Naam").Value,
WLand = Wijn.Attribute("Land").Value
Doesn't look right
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|