问题描述
我收到错误消息"根级别的数据无效。第1行,第1位。"在水晶报告查看器中。 PLZ帮我解决了这个错误...
I got error like "The data at the root level is invalid. Line 1, position 1." in crystal report viewer. plz help me to solve this error...
谢谢提前......
Thanks advance...
代码:
使用System;
使用System.Collections;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Web;
使用System.Web.SessionState;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.HtmlControls;
使用CrystalDecisions.Shared;
使用CrystalDecisions.CrystalReports.Engine;
使用CrystalDecisions.ReportSource;
使用System.IO;
使用System.Data.OleDb;
使用System.Configuration;
使用Oracle.DataAccess.Client;
使用System.Security;
$
名称空间feed.common.Accounts.Reports
{
///< summary>
/// frmCrystalReport的摘要说明。
///< / summary>
公共类frmCrystalReport:feed.library.frmRepHttpPost //System.Web.UI.Page
{
&NBSP;&NBSP;&NBSP; protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
&NBSP;&NBSP;&NBSP; protected System.Web.UI.WebControls.Label Label1;
&NBSP;&NBSP;&NBSP; protected System.Web.UI.WebControls.Label Label2;
&NBSP;&NBSP;&NBSP; protected System.Web.UI.WebControls.TextBox TextBox2;
&NBSP;&NBSP;&NBSP; protected System.Web.UI.WebControls.TextBox TextBox1;
&NBSP;&NBSP;&NBSP; protected System.Web.UI.WebControls.Button Button1;
&NBSP;&NBSP;&NBSP; protected feed.common.Accounts.Reports.frmCrystalReport1 frmCrystalReport11;
&NBSP;&NBSP;&NBSP; protected System.Web.UI.HtmlControls.HtmlInputFile file1;
&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; public frmCrystalReport()
&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; InitializeComponent();
&NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; private void Page_Load(object sender,System.EventArgs e)
&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //将用户代码设置为初始化页面
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; #region Web Form Designer生成的代码
&NBSP;&NBSP;&NBSP;覆盖受保护的void OnInit(EventArgs e)
&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; // CODEGEN:ASP.NET Web窗体设计器需要此调用。
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; InitializeComponent();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; base.OnInit(e);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; ///< summary>
&NBSP;&NBSP;&NBSP; ///支持Designer的必需方法 - 不要修改
&NBSP;&NBSP;&NBSP; ///使用代码编辑器的方法内容。
&NBSP;&NBSP;&NBSP; ///< / summary>
&NBSP;&NBSP;&NBSP; private void InitializeComponent()
&NBSP;&NBSP;&NBSP; {&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; this.frmCrystalReport11 = new feed.common.Accounts.Reports.frmCrystalReport1();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //this.Button1.Click + = new System.EventHandler(this.Button1_Click);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //this.Load + = new System.EventHandler(this.Page_Load);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; // frmCrystalReport11
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; this.frmCrystalReport11.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; this.frmCrystalReport11.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; this.frmCrystalReport11.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; this.frmCrystalReport11.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default;
&NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP; #endregion
&NBSP;&NBSP;&NBSP; private void Button1_Click(object sender,System.EventArgs e)
&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;试试
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; this.CrystalReportViewer1.Visible = true;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; ReportDocument cryRpt = new ReportDocument();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; cryRpt.Load(Sever.MapPath(" frmCrystalReport1.rpt"));;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; ConnectionInfo crConnectionInfo = new ConnectionInfo();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;表格CrTables;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; ParameterFieldDefinitions crParameterFieldDefinitions;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; ParameterFieldDefinition crParameterFieldDefinition;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; ParameterValues crParameterValues = new ParameterValues();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
$
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterDiscreteValue.Value = TextBox1.Text;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; TextBox1.Text = Convert.ToString(string.Format(" {0:MM / dd / yyyy}"));
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterFieldDefinition = crParameterFieldDefinitions [" fromDate"];
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterValues = crParameterFieldDefinition.CurrentValues;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterValues.Clear();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterValues.Add(crParameterDiscreteValue);
$
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterDiscreteValue.Value = TextBox2.Text;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; TextBox2.Text = Convert.ToString(string.Format(" {0:MM / dd / yyyy}"));
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterFieldDefinition = crParameterFieldDefinitions [" toDate"];
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterValues = crParameterFieldDefinition.CurrentValues;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterValues.Add(crParameterDiscreteValue);
$
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crConnectionInfo.ServerName ="" ;;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crConnectionInfo.DatabaseName ="" ;;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crConnectionInfo.UserID ="" ;;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crConnectionInfo.Password ="" ;;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //cryRpt.Load(Server.MapPath(" frmCrystalReport1.rpt"));
$
b $ b &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; CrTables = cryRpt.Database.Tables;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; foreach(CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crtableLogoninfo = CrTable.LogOnInfo;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; crtableLogoninfo.ConnectionInfo = crConnectionInfo;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; CrTable.ApplyLogOnInfo(crtableLogoninfo);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; CrystalReportViewer1.ReportSource = cryRpt;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; this.CrystalReportViewer1.ReportSource = Server.MapPath(" frmCrystalReport1.rpt");
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; CrystalReportViewer1.RefreshReport();
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; catch(Exception ex)
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; string script ="< script> alert('" + ex.Message +"');< / script>" ;;
$
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; Response.Write(ex.Message);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP;
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using System.IO;
using System.Data.OleDb;
using System.Configuration;
using Oracle.DataAccess.Client;
using System.Security;
namespace feed.common.Accounts.Reports
{
/// <summary>
/// Summary description for frmCrystalReport.
/// </summary>
public class frmCrystalReport : feed.library.frmRepHttpPost //System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected feed.common.Accounts.Reports.frmCrystalReport1 frmCrystalReport11;
protected System.Web.UI.HtmlControls.HtmlInputFile file1;
public frmCrystalReport()
{
InitializeComponent();
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.frmCrystalReport11 = new feed.common.Accounts.Reports.frmCrystalReport1();
//this.Button1.Click += new System.EventHandler(this.Button1_Click);
//this.Load += new System.EventHandler (this.Page_Load);
//
// frmCrystalReport11
//
this.frmCrystalReport11.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation;
this.frmCrystalReport11.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
this.frmCrystalReport11.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper;
this.frmCrystalReport11.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default;
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
this.CrystalReportViewer1.Visible = true;
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(Sever.MapPath("frmCrystalReport1.rpt"));
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
ParameterFieldDefinitions crParameterFieldDefinitions ;
ParameterFieldDefinition crParameterFieldDefinition ;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = TextBox1.Text;
TextBox1.Text = Convert.ToString(string.Format("{0:MM/dd/yyyy}"));
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["fromDate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crParameterDiscreteValue.Value = TextBox2.Text;
TextBox2.Text = Convert.ToString(string.Format("{0:MM/dd/yyyy}"));
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["toDate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crConnectionInfo.ServerName = "";
crConnectionInfo.DatabaseName = "";
crConnectionInfo.UserID = "";
crConnectionInfo.Password = "";
//cryRpt.Load(Server.MapPath ("frmCrystalReport1.rpt"));
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
CrystalReportViewer1.ReportSource = cryRpt;
this.CrystalReportViewer1.ReportSource = Server.MapPath ("frmCrystalReport1.rpt");
CrystalReportViewer1.RefreshReport ();
}
catch (Exception ex)
{
string script = "<script>alert('" + ex.Message + "');</script>";
Response.Write (ex.Message );
}
}
}
}
推荐答案
你可以在这里发布文件内容,你试图加载它。
can you post the file content here, the one you trying to load.
这篇关于根级别的数据无效。第1行,第1位。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!