[英]How do I print Crystal Reports?
我是Crystal报表打印的新人。 任何人都建议我在C#Desktop Application With Example(源代码)中打印Crystal报表的最佳方式。
尝试这个
private void button1_Click(object sender, EventArgs e)
{
CrystalReport1 rpt = new CrystalReport1();
SqlConnection cn = new SqlConnection("data source=localhost;initial catalog=acc;uid=sa;pwd=fantastic;");
cn.Open();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
cmd.Connection = cn;
cmd.CommandText = "select EmpNo, EName from Emp";
da.SelectCommand = cmd;
dt.Clear();
da.Fill(dt);
rpt.SetDataSource(dt);
rpt.PrintToPrinter(1, false, 0, 0);
}
您是否希望用户在需要时进行打印?
如果是这样,只需在CrystalReportViewer控件上启用print选项。
否则kashif提供的答案是编程方式。
这个对我有用。
private void PrintForm_Load(object sender, EventArgs e)
{
ReportDocument cry = new ReportDocument();
try
{
cry.Load(@"C:\Reports\CRYPT.rpt");//your report path
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=POS;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("Your Stored Procedure", con);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.Add("@Doc_No", System.Data.SqlDbType.VarChar, 50).Value = Globlevariable.PrintDocNo;
DataSet st = new DataSet();
sda.Fill(st, "DATA");
cry.SetDataSource(st);
cry.PrintToPrinter(1,false,0,0);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.