re-binding xml as memorystream to gridview

Last post 07-07-2009 4:55 PM by ejowens. 1 replies.

Sort Posts:

  • re-binding xml as memorystream to gridview

    07-02-2009, 5:14 PM
    • Member
      8 point Member
    • ejowens
    • Member since 12-14-2007, 4:54 PM
    • St Louis Metro area
    • Posts 90

    In wed dev 2005/asp.net 2.0...

    Using a datatable and csv file as input, I have built an xml doc; loaded the xml doc into a gridview and edited, added and deleted items.   Works quite well.  But in production, I have load balanced servers, so now that i'm successful with the file, i skip saving as physical file and create a memorystream: 

    xStream = New MemoryStream()

    xOL.Save(xStream)

    The stream gets bound with:

    Protected Sub gvEditOL_Bind()

    Dim xDS As New DataSet 

    xStream.Flush()

    xStream.Position = 0

    xDS.ReadXml(xStream)

    gvEditOL.DataSource = xDS

    gvEditOL.DataBind()

    End Sub

     

    When adding, editing or deleting an item, an error is thrown at the line xDS.ReadXML(xStream).  However, if the operation is cancelled everything is rebound with no problems.  Any ideas why this works for a file, but not a memorystream?

     

    Thanks,

     

    Eric

  • Re: re-binding xml as memorystream to gridview

    07-07-2009, 4:55 PM
    Answer
    • Member
      8 point Member
    • ejowens
    • Member since 12-14-2007, 4:54 PM
    • St Louis Metro area
    • Posts 90

    Quite a lack of response, so I guess i should put some more info in here...below is the error i get:

    System.Xml.XmlException was unhandled by user code
      Message="There are multiple root elements. Line 167, position 14." 

     

    here is the code for the gridview delete:

    Protected Sub gvEditOL_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvEditOL.RowDeleting
            Call gvEditOL_Bind()
            Dim xDS As DataSet = gvEditOL.DataSource
            xDS.Tables(0).Rows(gvEditOL.Rows(e.RowIndex).DataItemIndex).Delete()
            xDS.WriteXml(xStream)
            Call gvEditOL_Bind()
        End Sub


     

     

Page 1 of 1 (2 items)