delete button help(delete from xml)

need to delete customer from xml file

Page 1 of 1

2 Replies - 1842 Views - Last Post: 01 March 2009 - 05:28 PM Rate Topic: -----

#1 milton7888  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 11-September 08

delete button help(delete from xml)

Posted 28 February 2009 - 09:03 PM

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Const Path As String = "Customers.xml"
		Dim customers As New List(Of Customer)
		Dim xmlIn As New XmlTextReader(Path)
		xmlIn.WhitespaceHandling = WhitespaceHandling.None
		Dim i As Integer
		Dim c As Customer


		i = 0

		Do While xmlIn.Name <> "Customer"
			xmlIn.Read()
		Loop

		Do While xmlIn.Name = "Customer"
			Dim customer As New Customer
			xmlIn.ReadStartElement("Customer")
			customer.FirstName = xmlIn.ReadElementString("FirstName")
			customer.LastName = xmlIn.ReadElementString("LastName")
			customer.Email = xmlIn.ReadElementString("Email")
			customer.Password = xmlIn.ReadElementString("Password")
			customer.IDnumber = xmlIn.ReadElementString("IDnumber")
			customer.LoginID = xmlIn.ReadElementString("LoginID")
			xmlIn.ReadEndElement()

			If customer.LoginID = loginform1.UsernameTextBox.Text Then
				If customer.Password = loginform1.PasswordTextBox.Text Then
					i = i + 1
					c = customers.Item(i)
					customers -= c

				End If
			Else

			End If


		Loop
	End Sub
End Class



can someone tell me whats wrong with this code...i am trying to delete the customer that is equal to the text box's in the if statement....so i want to delete that whole customer, but with the code how i have it now it says operator"-" is not defined for types( for the line customers -=c ....i may be doing this all wrong.
if someone could look at this code and let me know how to get it to work, i would appreciate it.
THANKS
MILT

Is This A Good Question/Topic? 0
  • +

Replies To: delete button help(delete from xml)

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: delete button help(delete from xml)

Posted 01 March 2009 - 05:02 PM

When you are removing items from a List, you should use this (if you remove a specific object):

ListName.Remove (object)



If you want to remove an item based on the item ID, use this:

ListName.Remove (ID)


Was This Post Helpful? 0
  • +
  • -

#3 milton7888  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 11-September 08

Re: delete button help(delete from xml)

Posted 01 March 2009 - 05:28 PM

thanks for the help, i got it workin now....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1