2012-05-05 42 views

回答

0

你希望用户只打印时,他们要?

如果是这样,只需在CrystalReportViewer控件上启用打印选项即可。

否则由kashif提供的答案是编程方式。

3

试试这个

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