1

我希望我的報表顯示庫存量小於搜索文本框中插入的值的所有產品。有錯誤。在報表查看器中設置參數

這是存儲過程:

CREATE PROCEDURE [dbo].[GetInventoryReport] 
    @Stock int 
AS 
    SELECT * 
    FROM Product 
    WHERE Stock < @Stock 
    ORDER BY Stock ASC 

這是代碼,當用戶在搜索文本框中輸入值。

private void txtSearch_TextChanged(object sender, EventArgs e) 
{ 
    DataTable dtbl = GetInventoryReport_Result(); 

    rptInventoryStock.Visible = true; 
    rptInventoryStock.LocalReport.ReportPath = "InventoryReport.rdlc"; 
    rptInventoryStock.LocalReport.DataSources.Clear(); 

    rptInventoryStock.LocalReport.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl)); 

    this.rptInventoryStock.RefreshReport(); 
} 

這是GetInventoryReport_Result()功能:

private DataTable GetInventoryReport_Result() 
{ 
    DataTable dtbl = new DataTable(); 

    try 
    { 
     SqlCommand sqlCmd = new SqlCommand("GetInventoryReport", sqlCon); 
     sqlCmd.CommandType = CommandType.StoredProcedure; 
     sqlCmd.Parameters.AddWithValue("@Stock", txtSearch.Text.Trim()); 

     SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd); 
     sqlDa.Fill(dtbl); 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show(ex.Message, "Error Message"); 
    } 
    finally 
    { 
     if (sqlCon != null) 
      sqlCon.Close(); 
    } 

    return dtbl; 
} 

錯誤:

'Microsoft.Reporting.WinForms.LocalReport' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'Microsoft.Reporting.WinForms.LocalReport' could be found (are you missing a using directive or an assembly reference?)

回答

1

你錯過了.DataSources

替換:

rptInventoryStock.LocalReport.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl)); 

隨着

rptInventoryStock.LocalReport.DataSources.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl)); 
相關問題