通过打印到打印机打印我的水晶报告后数据丢失

本文关键字:打印 数据 报告 我的 打印机 水晶 | 更新日期: 2023-09-27 18:33:20

使用PrintToPrinter打印文档后,所有数据都会丢失,不知道为什么????

这段代码还有一个问题,我通过添加来纠正问题:

rpt.SetDatabaseLogon("u","p");

现在我打印了空文档。

这是我的代码:

protected void btnPrintToPrinter_Click(object sender, EventArgs e)
{
    int empno = Convert.ToInt32(Session["AnyVal"]);
    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

    string strQuery = "SELECT [View_EmplDetail].[Uni-Code], [View_EmplDetail].[FacultyCode], [View_EmplDetail].[EmpIDstr], [View_EmplDetail].[EngGivenName], [View_EmplDetail].[position_eng], [View_EmplDetail].[Emp_no], [View_EmplDetail].[GivenName], [View_EmplDetail].[position_name], [View_EmplDetail].[DariName], [Tbl_Dept].[EName], [View_EmplDetail].[photo] FROM   [MoHEDatabase].[dbo].[View_EmplDetail] [View_EmplDetail] INNER JOIN [MoHEDatabase].[dbo].[Tbl_Dept] [Tbl_Dept] ON [View_EmplDetail].[DepCode]=[Tbl_Dept].[DepCode] WHERE  [Emp_no] = @empno";
    SqlCommand command = new SqlCommand(strQuery, connection);
    command.CommandType = System.Data.CommandType.Text;
    command.Parameters.AddWithValue("@empno", empno);
    command.Connection = connection;
    command.Connection.Open();
    SqlDataAdapter da = new SqlDataAdapter(command);
    DataTable dt = new DataTable();
    da.Fill(dt);
    ReportDocument rpt = new ReportDocument();
    string _reportPath = Server.MapPath("..''Student''cardFinal.rpt");
    //rpt.Load(AppDomain.CurrentDomain.BaseDirectory + "''" + @"''Student''CardFinal.rpt");
    rpt.Load(_reportPath);
    rpt.SetDataSource(dt);
    emp_card_report_viewer.ReportSource = rpt;
    string sq = "";
    //{View_OrgStr1.Uni-Code}=0 and {View_OrgStr1.FacultyCode}=119 
    //sq = "{View_StudentAddNew.Student_ID}=" + Session["AnyVal"];
    if (Session["AnyVal"].ToString() != "")
    {
        sq = "{View_EmplDetail.Emp_no}=" + int.Parse(Session["AnyVal"].ToString());
    }
    //emp_card_report.Report.FileName = "../Student/CardFinal.rpt";
    emp_card_report_viewer.SelectionFormula = sq;
    //ConnectionInfo connInfo = new ConnectionInfo();
    //connInfo.ServerName = "172.16.0.15";
    //connInfo.DatabaseName = "MoHEMISDatabase";
    //connInfo.UserID = "hemis_admin";
    //connInfo.Password = "hemis@sabir";
    //TableLogOnInfos crtt = new TableLogOnInfos();
    //TableLogOnInfo crtto = new TableLogOnInfo();
    //Tables crtables;
    //crtables = rpt.Database.Tables;
    //foreach (CrystalDecisions.CrystalReports.Engine.Table crtable in crtables)
    //{
    //    crtto = crtable.LogOnInfo;
    //    crtto.ConnectionInfo = connInfo;
    //    //crtable.ApplyLogInInfo(crtto);
    //}
    ConnectionInfo connInfo1 = new ConnectionInfo();
   // connInfo1.ServerName = "server";
    setDBLOGONforReport(connInfo1);

    //emp_card_report_viewer.RefreshReport();

    //ConnectionInfo connInfo = new ConnectionInfo();
    //connInfo.ServerName = "server";
    //connInfo.DatabaseName = "MoHEDatabase";
    //connInfo.UserID = "hemis_admin";
    //connInfo.Password = "hemis@sabir";

    //setDBLOGONforReport(connInfo);

    CrystalDecisions.Shared.PageMargins pageMargins = new
    CrystalDecisions.Shared.PageMargins(0, 0, 0, 0);
    rpt.PrintOptions.ApplyPageMargins(pageMargins);
    rpt.PrintOptions.PrinterName = printerList.SelectedItem.Value;
    emp_card_report_viewer.RefreshReport();
    rpt.PrintToPrinter(1, false, 1, 1);

    rpt.Close();
    rpt = null;
}

通过打印到打印机打印我的水晶报告后数据丢失

答案:

我在水晶报告中使用了选择专家记录,我删除了选择专家中的所有公式,它起作用了.... :)