Hello everyone,
I don't have a question that needs answered in this thread but just would like some comments on the solution that I can up with for a particular requirement that was handed to me earlier today.
Basically, there is a stored procedure attached to one of our SQL Servers that returns different amounts and types of data based upon the input parameter (A client id) and management wanted to see this displayed web based and not inside of Crystal Reports. So begins my morning.
Initially I thought I could just bind this result set to a control and be done with it, unfortunately, my requirement was specific in how it needed to be displayed. The stored procedure returns a resultset that contains 2 columns: Category and Objective and the display should be as such:
[Category 1]
Objective 1
Objective 2
[Category 2]
Objective 1
Objective 2
And so on. Problem was is that my data was returned to me in the stored procedure like this:
[Category 1] [Objective 1]
[Category 1] [Objective 2]
[Category 2] [Objective 1]
[Category 2] [Objective 2]
I sat and thought about this and thought about this but there was no way (that I could think of) to transform this data inside a control based on the output of the stored procedure.
Obviously the way that management wanted this displayed is hierarchial and XML is great at storing hierarchial data but then came the next hurdle: I couldn't write anything to disk and everything had to be done in code. =
Basically this is what I came up with:
foreach(DataRow dr in dt.Rows)
{
if(sCategory == "")
{
sCategory = Convert.ToString(dr["ProblemDescription"]);
sXml += "<section><description>" + sCategory + "</description><objective>";
}
else if(sCategory != "" && sCategory != Convert.ToString(dr["ProblemDescription"]))
{
sCategory = Convert.ToString(dr["ProblemDescription"]);
sXml += "</objective></section><section>";
sXml += "<description>" + sCategory + "</description><objective>";
}
sXml += Convert.ToString(dr["objective"]);
}
sXml += "</objective></section></txplan>";
//Response.Write(sXml);
StringReader rdr = new StringReader(sXml);
ds.ReadXml(rdr);
foreach(DataTable t in ds.Tables)
{
foreach(DataRow dr in t.Rows)
{
dr["objective"] = Convert.ToString(dr["objective"]).Replace("[BEGIN]", "<li class='noMsg'>");
dr["objective"] = Convert.ToString(dr["objective"]).Replace("[END]", "</li>");
}
}
this.rprHistory.DataSource = ds;
this.rprHistory.DataBind();
Inside of the repeater, my data is displayed as was required by the initial requirement.
What I am wondering is if there is a more effective way to do something like this when the data has to be pulled directly from SQL and manipulated in code.
The one question I did have was with this line:
sXml += "</objective></section></txplan>";
That line closes the element and container of the XML document but if i add a closing </xml> tag to that string, at run time I get an error saying that it is an unexpected end tag? (FYI, The sXml string does contain an opening XML tag)
Does the DataSet appened /xml to the string when I call .ReadXml?
Anyway, comments would be greatly appreciated. ^^
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========