Push模式

WEB方式下】
 
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.Data.SqlClient;
       protected void Button_push_Click(object sender, EventArgs e)
    {
        string sql = "SELECT T1, T2, T3 FROM T where T1='a'";
        string DBConfig_sql =@"Data Source=SYWZSWL\SQLEXPRESS;Initial Catalog=Test;User ID=sa;Password=123456";
        DataSet ds = new DataSet();
            SqlConnection sqlCon = new SqlConnection(DBConfig_sql);
            SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);
            SqlDataAdapter sqlAd = new SqlDataAdapter();
            sqlAd.SelectCommand = sqlCmd;
            sqlAd.Fill(ds, "sql");
        CrystalReportSource1.ReportDocument.Load(Server.MapPath("CrystalReport.rpt"));  
        // 注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.”
CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables["sql"]);
//{?} 中的参数可以不用赋值,即使赋了值也不起作用。
       // CrystalReportSource1.ReportDocument.ParameterFields["Parm"].CurrentValues.AddValue("1234567");
        CrystalReportSource1.ReportDocument.ParameterFields["Title"].CurrentValues.AddValue(" 这时推模式的报表样例!" );
        CrystalReportSource1.DataBind();
 
        CrystalReportViewer1.ReportSource = CrystalReportSource1;
        CrystalReportViewer1.DataBind();
    }
 
//////
【WEB方式下】

using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.Data.SqlClient;
protected void Button_push_Click(object sender, EventArgs e)
{
string sql = "SELECT T1, T2, T3 FROM T where T1='a'";
string DBConfig_sql =@"Data Source=SYWZSWL\SQLEXPRESS;Initial Catalog= Test;UserID=sa;Password=123456";
DataSet ds = new DataSet();
SqlConnection sqlCon = new SqlConnection(DBConfig_sql);
SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);
SqlDataAdapter sqlAd = new SqlDataAdapter();
sqlAd.SelectCommand = sqlCmd;
sqlAd.Fill(ds, "sql");
CrystalReportSource1.ReportDocument.Load(Server.MapPath("CrystalReport.rpt"));
//注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.”
CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables["sql"]);
//{?}中的参数可以不用赋值,即使赋了值也不起作用。
// CrystalReportSource1.ReportDocument.ParameterFields["Parm"].CurrentValues.AddValue("1234567");
CrystalReportSource1.ReportDocument.ParameterFields["Title"].CurrentValues.AddValue("这时推模式的报表样例!");
CrystalReportSource1.DataBind();

CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.DataBind();
}
 
 
【FORM方式下】
 private void Form1_Load(object sender, EventArgs e)
        {
            // 推模式
            string sql = "SELECT T1, T2, T3 FROM T where T1='a'";
            string DBConfig_sql = @"Data Source=SYWZSWL\SQLEXPRESS;Initial Catalog=Test;User ID=sa;Password=123456";
            DataSet ds = new DataSet();
            SqlConnection sqlCon = new SqlConnection(DBConfig_sql);
            SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);
            SqlDataAdapter sqlAd = new SqlDataAdapter();
            sqlAd.SelectCommand = sqlCmd;
            sqlAd.Fill(ds, "sql");
            crystalReport1.Load(Application.StartupPath + "CrystalReport.rpt");
            crystalReport1.SetDataSource(ds.Tables["sql"]);
//{?} 中的参数可以不用赋值,即使赋了值也不起作用。
            // CrystalReportSource1.ReportDocument.ParameterFields["Parm"].CurrentValues.AddValue("1234567");
            crystalReport1.ParameterFields["Title"].CurrentValues.AddValue(" 这时推模式的报表样例!" );
 
            crystalReportViewer1.ReportSource = crystalReport1;
}
 
 
/////
【FORM方式下】
private void Form1_Load(object sender, EventArgs e)
{
//推模式
string sql = "SELECT T1, T2, T3 FROM T where T1='a'";
string DBConfig_sql = @"Data Source=SYWZSWL\SQLEXPRESS;Initial Catalog= Test;UserID=sa;Password=123456";
DataSet ds = new DataSet();
SqlConnection sqlCon = new SqlConnection(DBConfig_sql);
SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);
SqlDataAdapter sqlAd = new SqlDataAdapter();
sqlAd.SelectCommand = sqlCmd;
sqlAd.Fill(ds, "sql");
crystalReport1.Load(Application.StartupPath + "CrystalReport.rpt");
crystalReport1.SetDataSource(ds.Tables["sql"]);
//{?}中的参数可以不用赋值,即使赋了值也不起作用。
// CrystalReportSource1.ReportDocument.ParameterFields["Parm"].CurrentValues.AddValue("1234567");
crystalReport1.ParameterFields["Title"].CurrentValues.AddValue("这时推模式的报表样例!");

crystalReportViewer1.ReportSource = crystalReport1;
}

你可能感兴趣的:(push)