簡體   English   中英

c#將數據庫和參數傳遞給Crystal報表

[英]c# passing database and parameter to crystal report

我得到這個錯誤

參數字段和參數字段當前值的類型不兼容。

將數據庫和參數都傳遞給Crystal Reports時。

ReportDocument rd = new ReportDocument();

public string user;

public frmReport(string User)
{
        InitializeComponent();
        loadReport();
        this.user = User;
}

public void loadReport()
{
        rd.Load(@"C:\Users\Jeff Enad\Desktop\TEST1\Cebu Hallmark Hotel Management System\Cebu Hallmark Hotel Management System\cryReport.rpt");

        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=dbCebuHallmark;Integrated Security=True");

        SqlDataAdapter da = new SqlDataAdapter("GetAllReport", con);
        rd.SetParameterValue("UserPrinted", user); //This is the parameter
        da.SelectCommand.CommandType = CommandType.StoredProcedure;

        DataSet ds = new System.Data.DataSet();
        da.Fill(ds, "REPORT");

        rd.SetDataSource(ds);

        crystalReportViewer1.ReportSource = rd;
        crystalReportViewer1.Refresh();
}

SetParameterValue()導致錯誤。

誰能幫我解決這個問題? 我應該在存儲過程中還是在數據集中添加參數?

我只想將用戶名傳遞給具有數據庫的Crystal Report。

在此處輸入圖片說明

您必須在SqlAdapter SqlCommand對象中設置參數和值。 請參閱下面的更新代碼:

    public void loadReport()
    {
        rd.Load(@"C:\Users\Jeff Enad\Desktop\TEST1\Cebu Hallmark Hotel Management System\Cebu Hallmark Hotel Management System\cryReport.rpt");
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=dbCebuHallmark;Integrated Security=True");
        SqlDataAdapter da = new SqlDataAdapter("GetAllReport", con);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;
        DataSet ds = new System.Data.DataSet();
        da.Fill(ds, "REPORT");
        rd.SetDataSource(ds);
        rd.SetParameterValue("UserPrinted", user); //This is the parameter
        crystalReportViewer1.ReportSource = rd;
        crystalReportViewer1.Refresh();
    }

暫無
暫無

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

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