The data at the root level is invalid. Line 1, position 1.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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...

code:
using System;<br/>
using System.Collections;<br/>
using System.ComponentModel;<br/>
using System.Data;<br/>
using System.Drawing;<br/>
using System.Web;<br/>
using System.Web.SessionState;<br/>
using System.Web.UI;<br/>
using System.Web.UI.WebControls;<br/>
using System.Web.UI.HtmlControls;<br/>
using CrystalDecisions.Shared;<br/>
using CrystalDecisions.CrystalReports.Engine;<br/>
using CrystalDecisions.ReportSource;<br/>
using System.IO;<br/>
using System.Data.OleDb;<br/>
using System.Configuration;<br/>
using Oracle.DataAccess.Client;<br/>
using System.Security;<br/>
<br/>
<br/>
namespace feed.common.Accounts.Reports<br/>
{<br/>
/// <summary><br/>
/// Summary description for frmCrystalReport.<br/>
/// </summary><br/>
public class frmCrystalReport : feed.library.frmRepHttpPost //System.Web.UI.Page
<br/>
{<br/>
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;<br/>
protected System.Web.UI.WebControls.Label Label1;<br/>
protected System.Web.UI.WebControls.Label Label2;<br/>
protected System.Web.UI.WebControls.TextBox TextBox2;<br/>
protected System.Web.UI.WebControls.TextBox TextBox1;<br/>
protected System.Web.UI.WebControls.Button Button1;<br/>
protected feed.common.Accounts.Reports.frmCrystalReport1 frmCrystalReport11;<br/>
protected System.Web.UI.HtmlControls.HtmlInputFile file1;<br/>
<br/>
public frmCrystalReport()<br/>
{<br/>
InitializeComponent();<br/>
}<br/>
<br/>
private void Page_Load(object sender, System.EventArgs e)<br/>
{<br/>
// Put user code to initialize the page here<br/>
<br/>

<br/>
}<br/>
<br/>
<br/>
#region Web Form Designer generated code<br/>
override protected void OnInit(EventArgs e)<br/>
{<br/>
//<br/>
// CODEGEN: This call is required by the ASP.NET Web Form Designer.<br/>
//<br/>
InitializeComponent();<br/>
base.OnInit(e);<br/>
<br/>
}<br/>
<br/>
/// <summary><br/>
/// Required method for Designer support - do not modify<br/>
/// the contents of this method with the code editor.<br/>
/// </summary><br/>
private void InitializeComponent()<br/>
{ <br/>
this.frmCrystalReport11 = new feed.common.Accounts.Reports.frmCrystalReport1();<br/>
//this.Button1.Click += new System.EventHandler(this.Button1_Click);<br/>
//this.Load += new System.EventHandler (this.Page_Load);<br/>
// <br/>
// frmCrystalReport11<br/>
// <br/>
this.frmCrystalReport11.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation;<br/>
this.frmCrystalReport11.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;<br/>
this.frmCrystalReport11.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper;<br/>
this.frmCrystalReport11.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default;<br/>
<br/>
}<br/>
#endregion<br/>
<br/>
private void Button1_Click(object sender, System.EventArgs e)<br/>
{<br/>
<br/>
try<br/>
<br/>
{<br/>
<br/>
this.CrystalReportViewer1.Visible = true;<br/>
ReportDocument cryRpt = new ReportDocument();<br/>
cryRpt.Load(Sever.MapPath("frmCrystalReport1.rpt"));<br/>
<br/>
<br/>
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();<br/>
<br/>
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();<br/>
<br/>
ConnectionInfo crConnectionInfo = new ConnectionInfo();<br/>
<br/>
Tables CrTables;<br/>
<br/>
<br/>
<br/>
ParameterFieldDefinitions crParameterFieldDefinitions ;<br/>
<br/>
ParameterFieldDefinition crParameterFieldDefinition ;<br/>
<br/>
ParameterValues crParameterValues = new ParameterValues();<br/>
<br/>
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();<br/>
<br/>
<br/>
<br/>
crParameterDiscreteValue.Value = TextBox1.Text;<br/>
<br/>
TextBox1.Text = Convert.ToString(string.Format("{0:MM/dd/yyyy}"));
<br/>
<br/>
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;<br/>
<br/>
crParameterFieldDefinition = crParameterFieldDefinitions["fromDate"];<br/>
<br/>
crParameterValues = crParameterFieldDefinition.CurrentValues;<br/>
<br/>
<br/>
<br/>
crParameterValues.Clear();<br/>
<br/>
crParameterValues.Add(crParameterDiscreteValue);<br/>
<br/>
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);<br/>
<br/>
<br/>
<br/>
crParameterDiscreteValue.Value = TextBox2.Text;<br/>
<br/>
TextBox2.Text = Convert.ToString(string.Format("{0:MM/dd/yyyy}"));
<br/>
<br/>
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;<br/>
<br/>
crParameterFieldDefinition = crParameterFieldDefinitions["toDate"];<br/>
<br/>
crParameterValues = crParameterFieldDefinition.CurrentValues;<br/>
<br/>
<br/>
<br/>
crParameterValues.Add(crParameterDiscreteValue);<br/>
<br/>
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);<br/>
<br/>
<br/>
<br/>
crConnectionInfo.ServerName = "";<br/>
<br/>
crConnectionInfo.DatabaseName = "";<br/>
<br/>
crConnectionInfo.UserID = "";<br/>
<br/>
crConnectionInfo.Password = "";<br/>
//cryRpt.Load(Server.MapPath ("frmCrystalReport1.rpt"));<br/>
<br/>
<br/>
<br/>
CrTables = cryRpt.Database.Tables;<br/>
<br/>
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)<br/>
<br/>
{<br/>
<br/>
crtableLogoninfo = CrTable.LogOnInfo;<br/>
<br/>
crtableLogoninfo.ConnectionInfo = crConnectionInfo;<br/>
<br/>
CrTable.ApplyLogOnInfo(crtableLogoninfo);<br/>
<br/>

<br/>
}<br/>
CrystalReportViewer1.ReportSource = cryRpt;<br/>
this.CrystalReportViewer1.ReportSource = Server.MapPath ("frmCrystalReport1.rpt");<br/>
<br/>
CrystalReportViewer1.RefreshReport ();<br/>
<br/>
}<br/>
<br/>
catch (Exception ex)<br/>
<br/>
{<br/>
<br/>
string script = "<script>alert(" + ex.Message + ");</script>";<br/>
Response.Write (ex.Message );<br/>

<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
}<br/>
<br/>
}

View the full article
 
Back
Top