水晶报表

方法一:
//新方法
SqlDataSource1.SelectCommand = "select * from Data_Statistics_View";
SqlDataSource1.DataBind();
CrystalReportSource1.Report.FileName="CrystalReportsjtj.rpt";
CrystalDecisions.Web.DataSourceRef abc = new CrystalDecisions.Web.DataSourceRef();
abc.DataSourceID = "SqlDataSource1";
abc.TableName = "Data_Statistics_View";
CrystalReportSource1.Report.DataSources.Clear();
CrystalReportSource1.Report.DataSources.Add(abc);
CrystalReportSource1.DataBind();
CrystalReportViewer1.DataBind();

//新方法
SqlDataSource1.SelectCommand = "select case when style='1' then '短信' else '彩信' end as style , Op_time from a1_data";
SqlDataSource1.DataBind();
CrystalReportSource1.Report.FileName = "CrystalReportsjfxmonth.rpt";
CrystalDecisions.Web.DataSourceRef abc = new CrystalDecisions.Web.DataSourceRef();
abc.DataSourceID = "SqlDataSource1";
abc.TableName = "命令";
CrystalReportSource1.Report.DataSources.Clear();
CrystalReportSource1.Report.DataSources.Add(abc);
CrystalReportSource1.DataBind();
CrystalReportViewer1.DataBind();

方法二:
using (SqlConnection conn = ETong.ETongConn())
{
conn.Open();
string sql = "SELECT dbo.Data_Statistics.*, dbo.Busineesshall.Name, dbo.Area.County, dbo.Operation.Name AS OperationName FROM dbo.Data_Statistics INNER JOIN dbo.Busineesshall ON dbo.Data_Statistics.busineesshall_id = dbo.Busineesshall.BID INNER JOIN dbo.Area ON dbo.Area.AreaID = dbo.Busineesshall.Area_ID INNER JOIN dbo.Operation ON dbo.Operation.OperationID = dbo.Data_Statistics.businessID";
lblSQL.Text = sql;//为了保持状态

SqlDataAdapter myAdapter = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "Data_Statistics_View");
ReportDocument myReport = new ReportDocument();
myReport.Load(Server.MapPath("CrystalReport1.rpt"));
myReport.SetDataSource(ds.Tables[0]);//妈把,被搞死了.这里卡我了N久.热.,不要直接用ds对象
CrystalReportViewer1.ReportSource = myReport;

你可能感兴趣的:(报表)