簡體   English   中英

將數據源綁定到Crystal Reports

[英]Binding data source to Crystal Reports

我是Crystal Reports的新手

Crystal Viewer首先顯示數據表而不是提供數據源,並且每次都需要刷新Crystal Viewer。

private void crystalReportViewer1_Load(object sender, EventArgs e)
{
    string str = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString.ToString();
    SqlConnection con = new SqlConnection(str);
    string cellno = LoginUser.CellNo;
    SqlCommand cmd = new SqlCommand("SP_Get_CustomerByCellNo", con);

    cmd.Parameters.AddWithValue("@Cell", cellno);

    SqlDataAdapter da = new SqlDataAdapter(cmd);

    DataTable dt = new DataTable();
    da.Fill(dt);

    int i = dt.Rows.Count;

    ReportDocument rd = new ReportDocument();
    ConnectionInfo info = new ConnectionInfo();
    info.DatabaseName = "BillingAndAccounts";
    info.UserID = "sa";
    info.Password = "sa123";
    rd.VerifyDatabase();

    rd.Load(@"C:\Users\Abhinavu\Documents\Login\Login\OrderWindow.rpt");

    rd.SetDataSource(dt);
    crystalReportViewer1.ReportSource = rd; 
}

嗨,如果您要將數據集傳遞給報表,則必須使用類型化的數據集並將其用於報表中。

從我在這段代碼中所看到的,我可以想象您是基於數據集上的OLEDB和ADO.NET連接創建報表的。

ConnectionInfo info = new ConnectionInfo();
info.DatabaseName = "BillingAndAccounts";
info.UserID = "sa";
info.Password = "sa123";
rd.VerifyDatabase();

這里有2個鏈接,它們將向您展示如何使用ADO.NET數據集數據源創建報告

使用C#的DataSet和DataTable的Crystal Report

使用帶有數據集的C#創建Crystal報表

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM