我现在在做动态水晶报表出现了“表名无效”的错误,请大家帮帮忙!!!
代码://////////////////////////////////////////////////////////////////负责解释TableLogOnInfo类
using System;
using System.Data;
using System.Data.OracleClient;
using System.Windows.Forms;
using BusinessFacade;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
//负责解释ReportDocument类namespace WinUI.BusinessManage
{
/// <summary>
/// frmPrint 的摘要说明。
/// </summary>
public class frmPrint : System.Windows.Forms.Form
{
private CrystalDecisions.Windows.Forms.CrystalReportViewer CRV;
private CrystalDecisions.CrystalReports.Engine.TextObject GetTextObject1;
private crpAccount crp = new crpAccount(); /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; private string[] printColumn;
private DataSet ViewDS = new DataSet();
        private string Sql;
public frmPrint(string[] printColumn,string Sql)
{
this.printColumn = printColumn;
this.Sql =Sql;
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.CRV = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
this.SuspendLayout();
// 
// CRV
// 
this.CRV.ActiveViewIndex = -1;
this.CRV.DisplayGroupTree = false;
this.CRV.Dock = System.Windows.Forms.DockStyle.Fill;
this.CRV.Location = new System.Drawing.Point(0, 0);
this.CRV.Name = "CRV";
this.CRV.ReportSource = null;
this.CRV.Size = new System.Drawing.Size(744, 533);
this.CRV.TabIndex = 0;
// 
// frmPrint
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(744, 533);
this.Controls.Add(this.CRV);
this.Name = "frmPrint";
this.Text = "打印报表";
this.Load += new System.EventHandler(this.frmPrint_Load);
this.ResumeLayout(false); } #endregion private void frmPrint_Load(object sender, System.EventArgs e)
{
ReportPrint(this.Sql);
}
private void ReportPrint(string sql)
{
try
{
this.Cursor = Cursors.AppStarting;
ViewDS = (new BusinessManageBF()).GetViewByAccount(sql);
this.Cursor = Cursors.Default;
}
catch (Exception ex)
{
this.Cursor = Cursors.Default;
MessageBox.Show(ex.Message, "加载字段名信息错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
this.Cursor = Cursors.AppStarting;
crp.SetDataSource(ViewDS);
for(int i=0;i<this.printColumn.Length;i++)
{
GetTextObject1 = (crp.ReportDefinition.ReportObjects["text"+i] as CrystalDecisions.CrystalReports.Engine.TextObject);
GetTextObject1.Text = printColumn[i].ToString();
crp.DataDefinition.FormulaFields["c"+i].Text ="{V_account."+printColumn[i].ToString()+"}";
}
this.Cursor = Cursors.Default;
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo.ConnectionInfo.ServerName = "lzy";
logOnInfo.ConnectionInfo.UserID = "dtsms";
logOnInfo.ConnectionInfo.Password = "dtsms";
crp.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
CRV.ReportSource = crp;
}
}
}
printColumn[i].ToString();为视图的字段名称;