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

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default 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


    Sean Guest

  2. Similar Questions and Discussions

    1. Dynamically loading user control into Placeholder gives Object reference not set to an instance of an object
      I've created user controls that contain listboxes that are dynamically populated from the database. In the html view of the user control...
    2. Custom Control Problem :: Object reference not set to an instance of an object
      Hi All! I have the following Custom Control file... '########### WebUserControl1.ascx ############# <%@ Control Language="vb"...
    3. [WebMethod] System.NullReferenceException: Object reference not set to an instance of an object.
      Um, this isn't going to work, generally. Web services, as any web app (especially on Windows server 2003) are heavily sandboxed. The method you...
    4. Mysterious Error: Object reference not set to an instance of an object
      Hi There! I'm having a mysterious error right after I login using Forms Authentication in my ASP.NET app. Below is the error... Exception...
    5. HELP! Error Loading ASPX : Object Reference not set to an instance object
      Hello, When i run my aspx i get this weird error: System.NullReferenceException: Object reference not set to an instance of an object. at...
  3. #2

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

    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:#Ame0ViRDHA.2084@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


    Chad Tamplin Guest

  4. #3

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

    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" <chad_tamplin@cinfin.com> wrote in message
    news:e4ZixciRDHA.3796@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:#Ame0ViRDHA.2084@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
    >
    >

    Shahram Khosraviani Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139