简体   繁体   English

如何在Visual Studio 2010中将Crystal报表加载到报表查看器?

[英]How to load crystal report to report viewer in visual studio 2010?

I have tired by trying and trying but i am unable to do the job my problem is i want to load my crystal report to report view. 我已经厌倦了尝试,但是我无法完成工作,我的问题是我想加载我的水晶报告以报告视图。 i have made my crystal report and i have one windows form with report viewer, but how to show report in my report viewer what I am trying is 我已经制作了水晶报表,并且报表查看器有一个Windows窗体,但是如何在报表查看器中显示报表呢?

private void frmRptViewer_Load(object sender, EventArgs e)
{
        try
        {
            string SqlConnentionString = System.IO.File.ReadAllText("Connect.txt");


            SqlConnection con = new SqlConnection(SqlConnentionString);
            con.Open();
            SqlCommand com = new SqlCommand("SELECT EmployeeInfo.EmployeeCode, EmployeeInfo.DOJ,EmployeeInfo.GrossSalary,ea.Balance, EmployeeAdvance.MonthlyInst FROM  EmployeeInfo Left Outer JOIN EmployeeAdvance ON EmployeeInfo.EmployeeID = EmployeeAdvance.EmployeeID Left Outer Join (select employeeid,sum(dr)-sum(cr) as Balance from Deduction_Ledger where Deduction_type_ID = 1 Group By EmployeeiD ) ea on EmployeeInfo.employeeid = ea.employeeid where EmployeeInfo.dor is null", con);
            com.CommandType = CommandType.Text;
            SqlDataAdapter sdt = new SqlDataAdapter(com);
            DataTable ds = new DataTable();
            sdt.Fill(ds);
            EmpReport er = new EmpReport();
            er.SetDataSource(ds);
            reportViewer.ReportSource = er;
            reportViewer.Refresh();
            con.Close();
        }
        catch (Exception ex)
        {
            throw new ApplicationException(ex.Message);
        }
    }


}

please please somebody help me thanks in advance 请有人帮助我先谢谢

i'm not use C# 我不使用C#

but i noticed that your SQL statement select from three tables EmployeeInfo, ea and EmployeeAdvance 但我注意到您的SQL语句从三个表EmployeeInfo,ea和EmployeeAdvance中选择

in this case 在这种情况下

you need to pass DATASET contain three tables to your report, not DATATABLE 您需要将包含三个表的DATASET传递给报表,而不是DATATABLE

see my answer here , it may help you 在这里查看我的答案 ,可能会对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM