0

下面是导致错误的代码。作为 XSL 和 ASP.NET 的新手,我不太明白为什么会发生错误......

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="view.aspx.cs" Inherits="ININ.Marquee.Web.view" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Xml.Xsl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<html>
<head>

</head>


<body>

<form id="form1" runat="server" >
<div>
<script runat="server">

public string GetXMLAsString(XmlDocument myxml)
{
    StringWriter sw = new StringWriter();
        XmlTextWriter tx = new XmlTextWriter(sw);
        myxml.WriteTo(tx);

        string str = sw.ToString();// 
        return str;
}

public static string GetHtml(string xsltPath, string xml)
{
 MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(xml));
 XPathDocument document = new XPathDocument(stream);
 StringWriter writer = new StringWriter();
 XslCompiledTransform transform = new XslCompiledTransform();
 transform.Load(xsltPath);
 transform.Transform(document, null, writer);
 return writer.ToString();
}

public string details = string.Empty;

private void Page_Load(object sender, EventArgs e)
{   
    /******** - This the START of all the Database Stuff - ********/
    // Create a String to hold the database connection string.
    // NOTE: Put in a real database connection string here or runtime won't work
    string sdwConnectionString = @"Data Source = server; user id=username; password=password; Initial Catalog = database;";

    // Create a connection
    SqlConnection sdwDBConnection = new SqlConnection(sdwConnectionString);

    // Open the connection
    sdwDBConnection.Open();

    // Create a String to hold the query.
    string query = "SELECT * from IWrkgrpQueueStats WHERE ((substring(convert(char,dIntervalStart,120),1,10) = substring(convert(char,getdate(),120),1,10)) AND (cName IN ('Password','Arbour/CMBS/Other','Incident Escalation', 'OPOM/SOS/MyAccount','PC/Outlook','Overflow')) AND (cReportGroup='*' AND cHKey3='*' AND cHKey4='*'))";


    // Create a SqlCommand object and pass the constructor the connection string and the query string.
    SqlCommand queryCommand = new SqlCommand(query, sdwDBConnection);

    // Use the above SqlCommand object to create a SqlDataReader object.
    SqlDataReader queryCommandReader = queryCommand.ExecuteReader();

    //Create a DataTable object to hold all the data returned by the query.
    DataTable duplicatedataTable = new DataTable();

    // Use the DataTable.Load(SqlDataReader) function to put the results of the query into a DataTable.
    duplicatedataTable.Load(queryCommandReader);    

    // Open the connection
    sdwDBConnection.Close();

    DataSet ds = new DataSet("interactions");

    ds.Tables.Add(duplicatedataTable);

    string XML = ds.GetXML();

    details=GetHtml(Server.MapPath("~/Test.xsl"), XML); 

}
</script>   

<table width="100%">
<tr>
<td align="left">
<table width="100%" border="0">
<tr bgcolor="Silver">
<th align="center">

        <%= details %>
</th>
</tr>
</table>
</td>
</tr>
</table>

</div>
</form>

</body>
</html>

我已经查看了此代码和 .xsl 代码,似乎没有任何问题。谁能解释错误的含义以及导致错误的问题会发生在哪里?感谢你的协助。

4

1 回答 1

0

我相信您的问题是区分大小写的问题之一。

你为什么不试试:

string XML = ds.GetXml();

而不是

string XML = ds.GetXML();

希望有帮助。

于 2013-04-11T04:14:26.997 回答