Solved

problem data binding gridview to sql data returned as xml using for xml auto

Posted on 2010-08-20
9
487 Views
Last Modified: 2012-05-10
i have the xml below. it is being generated by a select that joins a couple tables (see the select here)

      SELECT      pm.ProjectMilestoneId,
                  pm.ProjectId,
                  pm.MilestoneCID,
                  pm1sc.CodeName as MilestoneText,        
                  pm.StartDate,        
                  pm.EndDate,        
                  pm.RAGStatusCID,        
                  pm2sc.CodeName as RAGStatusText,        
                  pm.CompletionStatusCID,        
                  pm3sc.CodeName as CompletionStatusText,        
                  pm.StatusText,        
                  pm.ReportingPriority,        
                  pm.Added,        
                  pm.LastUpdate,        
                  pm.UpdateBy  
      FROM ProjectMilestone pm  
                  INNER JOIN StatusCode pm1sc ON pm.MilestoneCID = pm1sc.CID  
                  INNER JOIN StatusCode pm2sc ON pm.RAGStatusCID = pm2sc.CID  
                  INNER JOIN StatusCode pm3sc ON pm.CompletionStatusCID = pm3sc.CID  
      WHERE pm.ProjectId = @ProjectId  
      ORDER by pm.StartDate desc
      for xml auto

the xml for this sql is below. and causes my C# data bind to fail. my c# code is as follows:

System.Xml.XmlReader xr = cmd.ExecuteXmlReader();
            DataSet ds2 = new DataSet();
            ds2.ReadXml(xr, XmlReadMode.InferSchema);
           
            DataView myDataView = new DataView();
            myDataView = ds2.Tables[0].DefaultView;

            gvMilestone.DataSource = myDataView;
            gvMilestone.DataBind();
<pm ProjectMilestoneId="100" ProjectId="2" MilestoneCID="18" StartDate="2010-08-18T00:00:00" EndDate="2010-08-19T00:00:00" RAGStatusCID="7" CompletionStatusCID="32" StatusText="something more wicked this way comes" Added="2010-08-16T00:00:00" LastUpdate="2010-08-18T14:06:26.510" UpdateBy="AMRS\ssalvati">
  <pm1sc MilestoneText="SAD/LLD Due                                       ">
    <pm2sc RAGStatusText="Red                                               ">
      <pm3sc CompletionStatusText="In-Progress                                       " />
    </pm2sc>
  </pm1sc>
</pm>
<pm ProjectMilestoneId="99" ProjectId="2" MilestoneCID="19" StartDate="1988-05-16T00:00:00" EndDate="2011-01-01T00:00:00" RAGStatusCID="7" CompletionStatusCID="35" StatusText="something really good is about to happen" ReportingPriority="1" Added="2010-08-10T00:00:00" LastUpdate="2010-08-18T11:04:09.660" UpdateBy="AMRS\ssalvati">
  <pm1sc MilestoneText="Hardware Required                                 ">
    <pm2sc RAGStatusText="Red                                               ">
      <pm3sc CompletionStatusText="Cancelled                                         " />
    </pm2sc>
  </pm1sc>
</pm>
<pm ProjectMilestoneId="991" ProjectId="2" MilestoneCID="1" StartDate="1933-05-16T00:00:00" EndDate="2033-01-01T00:00:00" RAGStatusCID="7" CompletionStatusCID="33" StatusText="testing text11111" Added="2010-08-10T00:00:00" LastUpdate="2010-08-17T18:44:31.813" UpdateBy="mshinder">
  <pm1sc MilestoneText="High                                              ">
    <pm2sc RAGStatusText="Red                                               ">
      <pm3sc CompletionStatusText="Delayed                                           " />
    </pm2sc>
  </pm1sc>
</pm>

Open in new window

0
Comment
Question by:realcoding
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 8

Expert Comment

by:mac-will
ID: 33485164
What is the error you are seeing?

btw. you don't need the "new DataView()" line as this new object is being removed in the following line.

Change to:

DataView myDataView = ds2.Tables[0].DefaultView;
0
 

Author Comment

by:realcoding
ID: 33485216
A field or property with the name 'MilestoneText' was not found on the selected data source

seems like the tables that get joined produces sub nodes in the xml instead of tossing all the values in the select into a single xml node as attributes. i think having this would solve the problem.
0
 
LVL 8

Expert Comment

by:mac-will
ID: 33485525
Yes that is probably true.

If you infer the schema than everything will be a node as the xml parser has no idea what should/shouldn't be an attribute.

If you know what the schema is why don't you explicitly create it first?

MAC
0
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 

Author Comment

by:realcoding
ID: 33486002
guys its simpler than that.
instead of for xml auto (creating new nodes)
i used for xml raw (creates all fields as attributes to a single noe)

and it works fine
0
 
LVL 8

Expert Comment

by:mac-will
ID: 33486607
Do you pre-define any columns in your grid?

I think generaly the dataset column names that are generated look like "Milestone_Text"

MAC
0
 
LVL 8

Expert Comment

by:mac-will
ID: 33486631
or rather "MilestoneText_Text"
0
 
LVL 8

Expert Comment

by:mac-will
ID: 33486638
try removing all pre-define columns and allow auto-generate columns
0
 

Accepted Solution

by:
realcoding earned 0 total points
ID: 33504460
i used for xml raw and it returns everything in a single xml node as an attribute.
0
 
LVL 8

Expert Comment

by:mac-will
ID: 33521027
What does the dataset table look like?
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question