水晶报表PUSH模式在WINFORM与WEBFORM中的应用

在WEBFORM中的源代码:

using System.Data.OleDb;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet da = getdata();
        CrystalReportSource1.ReportDocument.Load(Server.MapPath("CrystalReport.rpt"));
        //注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.”
       // CrystalReportSource1.ReportDocument.SetDataSource(ds);
        CrystalReportSource1.ReportDocument.SetDataSource(getdata());
        //{?}中的参数可以不用赋值,即使赋了值也不起作用。
        CrystalReportSource1.DataBind();
        CrystalReportViewer1.ReportSource = CrystalReportSource1;
        CrystalReportViewer1.DataBind();
    }

    public DataSet getdata()
    {
        string sql = "select * from teacher_info ";
        string DBConfig_sql = @"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=student;Data Source=ZHANGLIMEI";
        DataSet ds = new DataSet();
        OleDbConnection sqlcon = new OleDbConnection(DBConfig_sql);
        OleDbCommand sqlCmd = new OleDbCommand(sql, sqlcon);
        sqlcon.Open();
        OleDbDataAdapter sqlda = new OleDbDataAdapter();
        sqlda.SelectCommand = sqlCmd;
        sqlda.Fill(ds, "teacher_info");
        return ds;
    }

 

push模式在WINFORM中的应用,源代码如下:

 private void Form1_Load(object sender, EventArgs e)
        {
            DataSet ds = GetData();
            CrystalReport1 rc = new CrystalReport1();
            rc.SetDataSource(GetData());
            this.crystalReportViewer1.ReportSource = rc;
          }

        public DataSet GetData()
        {
            DataSet ds = new DataSet();
          //  string strConnection = "Provider=Microsoft.Jet.OleDb.4.0; Data Source="+ Application.StartupPath + "//BQN_CFM.mdb; Persist Security Info=False;";
           // string source = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + ";Persist Security Info=False;Jet OLEDB:Database Password=123";
            string strConnection = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Application.StartupPath + "//BQN_CFM.mdb; Persist Security Info=False;Jet OLEDB:Database Password=123";
          
            string strSql = "select * from BaseInfo_Personnel";
            OleDbConnection MyConnection = new OleDbConnection(strConnection);
            OleDbCommand cmd = new OleDbCommand(strSql, MyConnection);
            MyConnection.Open();
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            da.SelectCommand = cmd;
            da.Fill(ds, "BaseInfo_Personnel"); //填充数据集


            string strSql1 = "select * from BQN_System";
            OleDbCommand cmd1 = new OleDbCommand(strSql1, MyConnection);
            OleDbDataAdapter da1 = new OleDbDataAdapter(cmd1);
            da1.SelectCommand = cmd1;
            da1.Fill(ds, "BQN_System"); //填充数据集
            MyConnection.Close();
            return ds;
        }

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭