如何实现水晶报表和DataGrid的动态绑定?急啊!马上要交付了.
在学生管理系统的成绩查询这一Windows的form中,成绩查询功能已实现,可显示在DataGrid表中.查询过程是跟据班级,开课学期,课程名为条件实现查询,查询结果显示在form中的DataGrid控件中.现在我在这个form中添加一个CrystalReportViewer1,然后在项目中新建一个水晶报表,为空表.本意是想把显示在Datagrid中的表数据也显示在水晶报表中,然后把数据打印出来.源码如下.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;
namespace AdultMag
{
/// <summary>
/// SearcherCj 的摘要说明。
/// </summary>
public class SearcherCj : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txtXH;
private System.Windows.Forms.RadioButton radioONE;
private System.Windows.Forms.RadioButton radioALL;
private System.Windows.Forms.Button bnQuery;
private System.Windows.Forms.Button bnPrint;
private System.Windows.Forms.DataGrid dataGridCJCX;
private DataView dv;
private DataAccess access;
bool flag;
private System.Windows.Forms.Button bnAll;
private System.Windows.Forms.ComboBox comboXQ;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtKC;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBJ;
private System.Windows.Forms.Label label1;
private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
//public ReportDocument TheRpt=null;
public SearcherCj()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//this.crystalReportViewer1.DataBind();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//主要代码
-------------------------------------------------
access=new DataAccess();
dv=access.GetCJDataView();
dataGridCJCX.DataSource=dv;
CrystalReport1 TheRpt=new CrystalReport1();
TheRpt.SetDataSource(dataGridCJCX.DataSource);
this.crystalReportViewer1.ReportSource=TheRpt;
//this.crystalReportViewer1.DataBind();
TheRpt.Refresh();
-------------------------------------------------
}
由于帖子内容太长,后面内容略!
关键代码在两虚线之间.运行是老提示
未处理的“CrystalDecisions.CrystalReports.Engine.InvalidArgumentException”类型的异常出现在 crystaldecisions.crystalreports.engine.dll 中。
其他信息: 文件 C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\temp_4d10433c-5944-4f81-be03-581347fcb397.rpt 内出错:
无效表号。
我想请问错在哪儿,并且如何实现我想要的功能.即把DataGrid的数据也显示在水晶报表中.然后打印出来.实现水晶报表的动态绑定.