【问题标题】:How to print multiple instance of crystal report using single Crystal Report Viewer in c#如何在 c# 中使用单个 Crystal Report Viewer 打印多个 Crystal Report 实例
【发布时间】:2023-03-19 03:40:01
【问题描述】:


我正在尝试使用单个 Crystal Report Viewer 打印多个 Crystal Report。 我在数据库中有“n”个项目,我需要打印“n”个水晶报告。由于它本质上是动态的,所以我无法固定报表查看器的数量,所以我想使用单个报表查看器并使用“For循环”加载水晶报表。
我在数据集中创建了一个新的数据表,我试图从另一个数据表中输入值,但它没有解决,所以创建了参数字段并通过

循环

这是我的代码(我有 3 个参数字段以便于查看,只显示一个):

private void CRVtakeout_Load(object sender, EventArgs e)
    {
      try
           {
            string sqlqry = "Select KOTNo,Time,TableNo,WaiterName,ItemCode,ItemName,Quantity,Amount,Foodtype From tblOrder Where KOTNo=@kotno";
            SqlCommand cmd = new SqlCommand(sqlqry, connectionclass.con);
            cmd.Parameters.AddWithValue("@kotno", NewOrderBL.KOTNo);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet1 ds = new DataSet1();


            adapter.Fill(ds, "Takeout");
            //adapter.Fill(ds, "Takeout");
            string tableno = ds.Tables["Takeout"].Rows[i][2].ToString();
            tableno = tableno.Substring(6, 1);
            if (ds.Tables["Takeout"].Rows.Count == 0)

            {
                MessageBox.Show("No Data Found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (tableno == "T")
            {
                for (int i = 0; i < ds.Tables["Takeout"].Rows.Count; i++)
                {
                    crystalReportViewer1.RefreshReport();  
                ParameterFields paramFields = new ParameterFields();
                ParameterField paramField = new ParameterField();
                ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
                paramField.Name = "Billno";
                paramDiscreteValue.Value = ds.Tables["Takeout"].Rows[0][0].ToString();
                paramField.CurrentValues.Add(paramDiscreteValue);
                paramFields.Add(paramField);
printtakeout printtakeout = new printtakeout();
                printtakeout.SetDataSource(ds);
                crystalReportViewer1.ReportSource = printtakeout;
                System.Drawing.Printing.PrintDocument printdocument = new System.Drawing.Printing.PrintDocument();
                printtakeout.PrintOptions.PrinterName = printdocument.PrinterSettings.PrinterName;
                printtakeout.PrintOptions.PrinterName = "EPSON TM-U220 Receipt";
                printtakeout.PrintToPrinter(1, false, 0, 0);

                   }
  }
 }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        finally { connectionclass.disconnect(); }**strong text**
}

每次我这样做都会出错:

activex control 8856f961-340a-11d0-a96b-00c04fd705a2 无法实例化,因为当前线程不是单线程单元

如果我不使用参数字段,他们没有错误。 如果需要任何澄清,请告诉。 谢谢。

【问题讨论】:

    标签: c# crystal-reports dataset


    【解决方案1】:

    有一个例子可以做查询

    using (SqlConnection connection = new SqlConnection("connectionString"))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand();
                    command.CommandText = "SELECT * FROM Customers";
                    command.CommandType = CommandType.Text;
    
                    using (SqlDataReader objDataReader = command.ExecuteReader())
                    {
                        if (objDataReader != null)
                        {
                            while (objDataReader.Read())
                            {
                              // To get results...
                              // objDataReader["NameResultParam"];
                            }
                        }
                    }
              }
    

    【讨论】:

    • 如果我们以相同的客户为例,那么我需要为每个客户打印水晶报告,所以说 100 个客户,然后是 100 个单独的打印。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    相关资源
    最近更新 更多