S
Sean
Hi,
I am facing a problem, and i don't know why the error is being generated.
I am updating a datagrid with an XML file.
My code is
Protected Sub UpdateCommand(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
Try
Dim deletekey As String
dgpayer.EditItemIndex = -1
deletekey = dgpayer.DataKeys(CInt(E.Item.ItemIndex))
' these are the 4 new edited values
Dim newpaymentamount As String = (CType(E.Item.FindControl("txtepaymentamount"), TextBox).Text)
Dim newpaymentreference As String = (CType(E.Item.FindControl("txtepaymentreference"), TextBox).Text)
Dim newcomment As String = (CType(E.Item.FindControl("txtecomment"), TextBox).Text)
Dim newdatetime As String = (CType(E.Item.FindControl("txtedatetime"), TextBox).Text)
' Response.Write(newcomment)
'load the XML
Dim doc As New XmlDocument()
doc.Load("c:\Inetpub\wwwroot\Cashier\cashier.xml")
Dim node As XmlElement = doc.SelectSingleNode("cashier/tag[@section=payer-" & lbunique.Text & "']")
' setting the attributes to the xml node to replace the values with the new ones
node.SetAttribute("payment_amount", newpaymentamount)
node.SetAttribute("payment_reference", newpaymentreference)
node.SetAttribute("comment", newcomment)
node.SetAttribute("datetime", newdatetime)
' save the xml
doc.Save("c:\Inetpub\wwwroot\Cashier\cashier.xml")
'display the datagrid
viewgrid()
Catch Exc As Exception
lbError.Text = "Update DataGrid Error: " & Exc.Message
End Try
End Sub
And my XML file is
<?xml version="1.0" standalone="yes"?>
<cashier>
<tag param1="payer-16" param2="Reeves" param3="1" param4="324" payment_amount="123.00" payment_reference="123" comment="asf" datetime="7/8/2003" />
<tag param1="payer-14" param2="Johnny" param3="3" param4="345" payment_amount="113.00" payment_reference="123" comment="asf" datetime="7/8/2003" />
<tag param1="payer-14" param2="Joahns" param3="2" param4="325" payment_amount="135.00" payment_reference="123" comment="asf" datetime="7/8/2003" />
</cashier>
The error is generated why i set the attributes to replace the old values with the new ones.
The error message is 'Object reference not set to an instance of an object.'
Any help is appreciated.
I am facing a problem, and i don't know why the error is being generated.
I am updating a datagrid with an XML file.
My code is
Protected Sub UpdateCommand(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
Try
Dim deletekey As String
dgpayer.EditItemIndex = -1
deletekey = dgpayer.DataKeys(CInt(E.Item.ItemIndex))
' these are the 4 new edited values
Dim newpaymentamount As String = (CType(E.Item.FindControl("txtepaymentamount"), TextBox).Text)
Dim newpaymentreference As String = (CType(E.Item.FindControl("txtepaymentreference"), TextBox).Text)
Dim newcomment As String = (CType(E.Item.FindControl("txtecomment"), TextBox).Text)
Dim newdatetime As String = (CType(E.Item.FindControl("txtedatetime"), TextBox).Text)
' Response.Write(newcomment)
'load the XML
Dim doc As New XmlDocument()
doc.Load("c:\Inetpub\wwwroot\Cashier\cashier.xml")
Dim node As XmlElement = doc.SelectSingleNode("cashier/tag[@section=payer-" & lbunique.Text & "']")
' setting the attributes to the xml node to replace the values with the new ones
node.SetAttribute("payment_amount", newpaymentamount)
node.SetAttribute("payment_reference", newpaymentreference)
node.SetAttribute("comment", newcomment)
node.SetAttribute("datetime", newdatetime)
' save the xml
doc.Save("c:\Inetpub\wwwroot\Cashier\cashier.xml")
'display the datagrid
viewgrid()
Catch Exc As Exception
lbError.Text = "Update DataGrid Error: " & Exc.Message
End Try
End Sub
And my XML file is
<?xml version="1.0" standalone="yes"?>
<cashier>
<tag param1="payer-16" param2="Reeves" param3="1" param4="324" payment_amount="123.00" payment_reference="123" comment="asf" datetime="7/8/2003" />
<tag param1="payer-14" param2="Johnny" param3="3" param4="345" payment_amount="113.00" payment_reference="123" comment="asf" datetime="7/8/2003" />
<tag param1="payer-14" param2="Joahns" param3="2" param4="325" payment_amount="135.00" payment_reference="123" comment="asf" datetime="7/8/2003" />
</cashier>
The error is generated why i set the attributes to replace the old values with the new ones.
The error message is 'Object reference not set to an instance of an object.'
Any help is appreciated.