Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2003, 04:13 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGrid .. XML .. Errors to update

Hi,
I have been trying to solve this problem since morning, and haven't really come up with a solution. it is frustrating. please help.

i have a datagrid and got a delete column

<asp:datagrid id="dgdocument" runat="server" AutoGenerateColumns="False" EnableViewState="True" OnDeleteCommand="DeleteCommand">
<Columns>
 <asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
 <asp:BoundColumn DataField="Param1" HeaderText="Param1"></asp:BoundColumn>
 <asp:BoundColumn DataField="Param2" HeaderText="Param2"></asp:BoundColumn>
 <asp:BoundColumn DataField="Param3" HeaderText="Param3"></asp:BoundColumn>
</Columns>
</asp:datagrid>


and the VB code is

Sub DeleteCommand(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
 Dim deletekey = dgdocument.DataKeys(CInt(E.Item.ItemIndex))
 Response.Write(deletekey)

 'load the XML
 Dim doc As New XmlDocument()
 doc.Load("c:\Inetpub\wwwroot\Cashier\cashier.xml")
 Dim onode As XmlElement = doc.SelectSingleNode("cashier/tag[@section='workinformation-" & lbunique.Text & "' and @param1='& deletekey & ' ]")

 'not to sure whether this is right
 Dim oldNode As XmlNode = doc.RemoveChild("cashier/tag[@section='workinformation-" & lbunique.Text & "' and @param1='& deletekey & ' ]")

 ' ---------------- this is not right : deleting the node
 onode.RemoveChild(oldNode)

 ' save the xml
 doc.Save("c:\Inetpub\wwwroot\Cashier\cashier.xml")

 dgdocument.EditItemIndex = -1
 viewxmldtn()
End Sub

and the XML file is

<cashier>
  <tag section="work-14" param1="1" param2="345" param3="7/9/2003 08:00 AM" />
  <tag section="work-14" param1="2" param2="345" param3="7/9/2003 08:00 AM" />
  <tag section="work-14" param1="3" param2="345" param3="7/9/2003 08:00 AM" />
</cashier>
Param1 is a unique field.


What should the right syntax be to remove the node from the XML file.

Any help is appreciated.

Thank You
 
Old July 10th, 2003, 03:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I can see a few things straight off, I'm assuming onode is the one you want to delete:
1. you have "cashier/tag[@section='workinformation-" ..., but your XML example shows it should be "cashier/tag[@section='work-"
2. you are missing some quotes near the end, where you have ...@param1='& deletekey & ' ]"), you want ...@param1='"& deletekey & "' ]")

so if you fix those two you should then have the node you want to delete stored in onode. Then I think you need to:
1. Ditch the line that starts Dim oldNode As XmlNode = ...
2. change the line onode.RemoveChild(oldNode) to onode.parentNode.RemoveChild(onode)

That should do it for you.

hth
Phil
 
Old July 10th, 2003, 09:16 AM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank You. The quotes at the end were missing. and the tag for work had been changed too.

Thank You once again for your help. :-)








Similar Threads
Thread Thread Starter Forum Replies Last Post
Update.Entry causes HTTP 500 errors ?? jodojan ASP.NET 1.0 and 1.1 Basics 3 September 7th, 2007 06:28 PM
Datagrid.update() and DataAdapter.Update aarunlal ASP.NET 2.0 Professional 2 February 23rd, 2006 11:41 PM
Binding a datagrid on errors drono ASP.NET 1.0 and 1.1 Professional 3 June 9th, 2005 08:30 AM
ASP Insert/Update code causes errors lewdogg Classic ASP Databases 4 January 25th, 2005 04:24 AM
ADO UPDATE Errors rborloz Pro VB Databases 0 January 20th, 2005 04:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.