我在aspx.cs文件中的Page_Load中有以下内容:
public abstract partial class ViewInvoices : DotNetNuke.Entities.Modules.PortalModuleBase
{
protected void Page_Load(object sender, EventArgs e)
{
using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DNN"].ConnectionString))
{
DataSet ds = new DataSet();
DataTable salesOrders = new DataTable();
DataTable salesOrdersDetail = new DataTable();
DataTable recurringSalesOrders = new DataTable();
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
command.Connection = connection;
command.CommandText = @"SELECT * FROM REVINDEX_STOREFRONT_SALESORDER WHERE STATUS = 1";
System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(command);
adapter.Fill(salesOrders);
System.Data.SqlClient.SqlCommand comm2 = new System.Data.SqlClient.SqlCommand();
command.Connection = connection;
command.CommandText = @"SELECT * FROM REVINDEX_STOREFRONT_SALESORDERDETAIL inner join
REVINDEX_STOREFRONT_SALESORDER on REVINDEX_STOREFRONT_SALESORDERDETAIL.SALESORDERID =
REVINDEX_STOREFRONT_SALESORDER.SALESORDERID WHERE SALESORDER.STATUS = 1";
System.Data.SqlClient.SqlDataAdapter adapter2 = new System.Data.SqlClient.SqlDataAdapter(command);
adapter.Fill(salesOrdersDetail);
adapter.Fill(recurringSalesOrders);
MemoryStream ms = new MemoryStream();
salesOrders.WriteXml(ms, XmlWriteMode.WriteSchema);
salesOrdersDetail.WriteXml(ms, XmlWriteMode.WriteSchema);
recurringSalesOrders.WriteXml(ms, XmlWriteMode.WriteSchema);
ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms);
string xml = sr.ReadToEnd();
ms.Close();
return xml;
}
}
}
我的目标是将数据表的内容发送到xml文件并将其保存到磁盘以供我的DNN模块的用户界面参考。当我尝试运行它时,我收到以下错误:
Since 'DNNSharp.Revindex.ViewInvoices.Page_Load(object, System.EventArgs)' returns void,
a return keyword must not be followed by an object expression
此错误是否表明我在Page_Load事件中错误地放置了逻辑?如果是这样,我应该定义一个单独的事件/方法来创建数据表并将结果写入XML文件吗?
谢谢!
答案 0 :(得分:2)
页面加载事件处理程序不应返回值...将最后一行从return xml;
更改为简单return;
或只删除它。