I have created two aspx which retrives data from an SQL-server and
writes the responses to the Treeview-Control. I have added my two code
samples at the bottom.
The thing is that when i try to run my page with the treeview I recieve the
following error - There is invalid data at the root level. Line 1,
position
1. Exception Details: System.Xml.XmlException: There is invalid data at the
root level. Line 1, position 1.
Example of my xml-file
<TREENODES>
<TreeNode Text="Test " TreeNodeSrc="Samplegroups.aspx?study_ID=1" />
</TREENODES>
Does any of you have an explaination or idea about what to do.
Thanks in advance
Lars
TopNodes
-----------------------------------------------------------
<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.Configuration"%>
<Script runat="server">
private void Page_Load(object sender, System.EventArgs e){
SqlConnection sqlConn = new
SqlConnection(ConfigurationSettings.AppSettings["conStr"]);
string qryStr = "SELECT StudyName AS Text,
'Samplegroups.aspx?study_ID=' + LTRIM(STR(Study_ID))" +
"AS TreeNodeSrc FROM Study As TreeNode FOR XML AUTO, XMLDATA";
SqlCommand cmdStudy = new SqlCommand(qryStr, sqlConn);
sqlConn.Open();
System.Data.DataSet dsStudies = new DataSet();
dsStudies.ReadXml(cmdStudy.ExecuteXmlReader(), XmlReadMode.Fragment);
dsStudies.DataSetName = "TREENODES";
dsStudies.WriteXml(Response.OutputStream);
sqlConn.Close();
}
</Script>
Nodes
---------------------------------------------------------
<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.Configuration"%>
<Script runat="server">
private void Page_Load(object sender, System.EventArgs e){
SqlConnection sqlConn = new
SqlConnection(ConfigurationSettings.AppSettings["conStr"]);
string qryStr = "SELECT SamIdent AS Text FROM SampleGroup AS TREENODE"
+
"WHERE Study_ID=@study_ID FOR XML AUTO, XMLDATA"
SqlCommand cmdSampleGroup = new SqlCommand(qryStr, sqlConn);
cmdSampleGroup.Parameters.Add( New SqlParaameter( "@study_ID",
Request.QueryString("study_ID")));
sqlConn.Open();
System.Data.DataSet dsSampleGroups= new DataSet();
dsSampleGroups.ReadXml(cmdSampleGroup.ExecuteXmlReader(),
XmlReadMode.Fragment);
dsSampleGroups.DataSetName = "TREENODES";
sqlConn.Close();
}
</Script>