[英]How to print multiple instance of crystal report using single Crystal Report Viewer in c#
I am trying to print multiple crystal report using single Crystal Report Viewer. 我正在尝试使用单个Crystal Report Viewer打印多个Crystal报表。 I have 'n' number of items in a database and I need to print 'n' crystal reports. 我的数据库中有n个项目,我需要打印n个水晶报表。 As it is dynamic in nature so I cannot fix number of Report Viewer, so I thought to use single Report Viewer and load crystal report using 'For loop'. 由于它本质上是动态的,因此我无法确定Report Viewer的数量,因此我考虑使用单个Report Viewer并使用“ For循环”加载Crystal报表。
I created a new datatable in dataset and I was trying to put value from another datatable it didnt worked out so created parameter fields and is putting values in through 我在数据集中创建了一个新的数据表,而我试图从另一个数据表中获取值,但该数据表无法解决,因此创建了参数字段,并通过
For Loop 对于循环
Here my code(I have 3 parameter fields for ease of viewing showing only one): 这是我的代码(我有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**
}
Each time I do it gives error : 每次我这样做都会出错:
activex control 8856f961-340a-11d0-a96b-00c04fd705a2 cannot be instantiated because the current thread is not a single-thread apartment 由于当前线程不是单线程单元,因此无法实例化activex控件8856f961-340a-11d0-a96b-00c04fd705a2
If I dont use parameter field theirs no error. 如果我不使用参数字段,则不会出错。 If any clarification needed please do tell. 如果需要任何澄清,请告诉。 Thanks . 谢谢 。
There is an example to do queries 有一个做查询的例子
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"];
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.