2012-05-05 78 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); 
} 
相關問題