2

PrintToPrinterを使用してドキュメントを印刷した後、すべてのデータが失われます。理由がわかりませんか????

このコードにはもう1つの問題がありました。次を追加して、問題を修正しました。

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;
}
4

1 に答える 1

1

答え:

クリスタルレポートでSelectExpertRecordを使用していましたが、Select Expertですべての数式を削除すると、機能しました.... :)

于 2012-05-08T09:33:04.477 に答える