Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem Loading XML into dataset and binding to gridview

Newbie
 
Join Date: Jun 2007
Location: Atlanta, Ga
Posts: 11
#1: Jun 17 '07
This is a 2 part question:

Part 1:
I am accesing a web service that returns an xml string of user information. I am attempting to load the XML into an XMLDocument, save the document, load it into a dataset, and bind the dataset to a gridview.

I'm not sure if it's neccesary to save the XML file to disk, but I wanted to make sure it was well formed. It is.

No exceptions are caught during the loading and binding process, but my gridview only displays the first 2 attribute values of the parent node (the first datarow). Any ideas as to why this would happen?

Part 2:
I need to filter the data based on several attribute values in the XML file. Is this more efficient pre-dataset or post-dataset? At a high-level, how would one go about doing either?

Here is the code:

Private Sub GetMembers()
Dim tSessionId As String = Session("TimssSessionId").ToString
Dim wsTimssCustomer As New wsTimssCustomer.TIMSSCustomer
Dim xmlDocMembers As New XmlDocument
Dim oDataSet As DataSet
Dim sXMLMembersFile As String = Server.MapPath("xmldocuments/members.xml")

'Open a new call to the web service thru the web reference
Dim wsTimssCusGet As wsTimssCustomer.TIMSSCustomer = New wsTimssCustomer.TIMSSCustomer()

'Use the GetCustomers Web Service passing session id, field names, values
Dim MemberXml As String = wsTimssCusGet.GetCustomers(tSessionId, "FirstName, LastName", "Jason, Abney")

'Load the return in an XML Document
xmlDocMembers.LoadXml(MemberXml)
xmlDocMembers.Save(sXMLMembersFile)

Try
oDataSet = new DataSet
oDataSet.ReadXml(sXMLMembersFile)

'Bind it to the gridview
gvMembers.DataSource = oDataSet.Tables(0)
gvMembers.DataBind()
Catch ex As Exception
Response.Write(ex.ToString)
End Try
End Sub

kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Jun 17 '07

re: Problem Loading XML into dataset and binding to gridview


Welcome to TSDN. I assume both problems could be resolved through ado.net and modifying queries. HTH.
Newbie
 
Join Date: Jun 2007
Location: Atlanta, Ga
Posts: 11
#3: Jun 17 '07

re: Problem Loading XML into dataset and binding to gridview


Thank you for your response. That's a little ambiguous however. Could you elaborate please?

Thank you
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#4: Jun 18 '07

re: Problem Loading XML into dataset and binding to gridview


Here is an article that may help:
Programmatically using ADO.NET and XML
Newbie
 
Join Date: Jun 2007
Location: Atlanta, Ga
Posts: 11
#5: Jun 18 '07

re: Problem Loading XML into dataset and binding to gridview


That has very little to do with what I am trying to accomplish. Thanks anyway.
TRScheel's Avatar
Expert
 
Join Date: Apr 2007
Location: Iowa
Posts: 624
#6: Jun 18 '07

re: Problem Loading XML into dataset and binding to gridview


Edited to read more into the problem...


Have you tried binding directly into the DataSet?


Also, can you post the HTML of your gridview?
Newbie
 
Join Date: Jun 2007
Location: Atlanta, Ga
Posts: 11
#7: Jun 18 '07

re: Problem Loading XML into dataset and binding to gridview


I am binding directly to the dataset. Here's the code:
oDataSet = New DataSet
oDataSet.ReadXml(sXMLMembersFile)
gvMembers.DataSource = oDataSet
gvMembers.DataBind()


Here's the HTML of the gridview:
<asp:GridView ID="gvMembers" runat="server">
</asp:GridView>
Reply