473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Object reference not set to an instance of an object. .......... Error .... Please Help

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.

--
Thank You,
Sean
Nov 19 '05 #1
2 4452
The error is thrown because you are not finding any nodes when you call the
following line..

Dim node As XmlElement = doc.SelectSingleNode("cashier/tag[@section=payer-"
& lbunique.Text & "']")

It looks like your XPath query is not correct. I don't see an attribute
called 'section' in your xml.

Chad

"Sean" <nospam@> wrote in message
news:#A**************@TK2MSFTNGP11.phx.gbl...
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.

--
Thank You,
Sean
Nov 19 '05 #2
Sorry,

i did make a change to the xml file.

the xml file is

<?xml version="1.0" standalone="yes"?>
<cashier>
<tag section="work-14" param2="123" param2="NOTARY" param3="7/9/2003 08:00
AM" param5="PENDING" param6="3" param7="1000341" />
<tag Section="payer-14" param2="New York" param2="1" param3="CHECK/MO"
payment_amount="123.00" payment_reference="12" param4="No" comment="asdf"
datetime="7/9/2003" />
</cashier>

phew, it worked.

now, the problem is that there is no unique key in the xml file, so it
replaces the first occurance of the payer attribute.

Should i change the xml file, in order to generate a unique field to each of
the tags, or should i combine the elements in the SelectSingleNode into
'and' statement ?

Just wondering what is the better approach.
Dim node As XmlElement =
doc.SelectSingleNode("cashier/tag[@Section='payerinformation-" &
lbunique.Text & "']")


"Chad Tamplin" <ch**********@cinfin.com> wrote in message
news:e4**************@tk2msftngp13.phx.gbl...
The error is thrown because you are not finding any nodes when you call the following line..

Dim node As XmlElement = doc.SelectSingleNode("cashier/tag[@section=payer-" & lbunique.Text & "']")

It looks like your XPath query is not correct. I don't see an attribute
called 'section' in your xml.

Chad

"Sean" <nospam@> wrote in message
news:#A**************@TK2MSFTNGP11.phx.gbl...
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.

--
Thank You,
Sean

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
4
by: Frawls | last post by:
Hi, I get the following error when trying to run a search on my aspx site, this error only occours if the product im searching for does not exist. Can anybody explain this please and help me...
1
by: Dave | last post by:
Hello I hope someone can give me some idea of what is causing this error. I can run though my asp app locally no problem but when i put it on the server i get this error, any help at all whould be...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
3
by: nemo | last post by:
Hi, My application works fine on the localhost but spits this error as soon as I put it on the server. I know this error occurs when an object has not been instantiated prior to a reference, but...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
3
by: Brano | last post by:
HI all, I have a problem i have a web application that was working fine and this morning when i run it and click on a button that does Reponse.Redirect to a page i get this error : Server...
5
by: eBob.com | last post by:
I am trying to change some Structures to Classes. The Classes now look like this ... Public Class OneAttr Public AttrName As String Public Column As String Public Caption As String End Class...
2
by: Hennie | last post by:
I Get the following error all of a sudden: I do not know what is wrong or where to start looking. I added the Debug="true" directive at the top of the page, but it does not help at all. What...
1
by: Nathan Sokalski | last post by:
I have a UserControl that I declare programmatically as follows: Dim userctrl as New rightside_portal() The codebehind file for this UserControl looks like the following: Partial Public...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.