1

私はCrystalレポート印刷の新参者です。誰もがC#デスクトップアプリケーションの例(ソースコード)でCrystalレポートを印刷する最良の方法を提案してくれます。

4

3 に答える 3

4

これを試して

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);
}
于 2012-05-06T21:46:06.363 に答える
0

ユーザーが必要なときに印刷するだけにしますか?

その場合は、CrystalReportViewerコントロールで印刷オプションを有効にしてください。

そうでなければ、kashifによって提供される答えはプログラム的な方法です。

于 2012-05-06T23:52:45.900 に答える
0

これは私のために働きます。

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);
        }
    }
}
于 2018-03-21T18:29:40.510 に答える