2012-06-24 21 views
0

我有一個帶有EF的ASP.NET MVC 4項目。我有一個ASPX Web頁面來顯示ReportControl for RDLC報告。ASP.NET RDLC:從Tablix中的另一個表中顯示字段

那裏我有2個表格:訂單代理。在我的報告中,我想顯示(在Tablix中)所有的訂單。

OrderNo | OrderDate | OrderTotal | OrderStatus |代理

(代理列是代理的名稱:「Agent.Name」)

問:我怎樣才能在Tablix的另一個表(代理)顯示的字段(Agent.Name) ?

if (!IsPostBack) 
    { 
    var qry = FROM o in db.Orders 
       //JOIN a in d.Agents on o.idAgent equals a.idAgent 
       SELECT o; // 
    ReportDataSource dataSource = new ReportDataSource("DataSetOrder_Agent", qry); 
    ReportViewerOrders.LocalReport.DataSources.Add(dataSource); 
    } 

回答

0
  1. 使用SP:

    CREATE PROCEDURE [dbo].spAgentOrders  
    (
    @fromdate DATE, 
    @todate DATE 
    ) 
    AS 
    DECLARE @from DATE = @fromdate, @to DATE = @todate 
    SELECT o.orderbo, o.orderdate, o.ordervalue, o.status, a.name 
    FROM orders o 
    JOIN agent a on o.id_agent = a.id_agent 
    WHERE o.orderdate between @from and @to 
    RETURN 
    

更新模型,加上SP作爲一個返回複雜類型的函數導入。 2.網絡表單代碼隱藏:

if (!IsPostBack) 
{ 
//... 
var qry = db.spAgentOrders(tbFrom.Text, tbTo.Text); 

ReportDataSource dataSource = new ReportDataSource("DataSetOrder_Agent", qry); 
ReportViewerOrders.LocalReport.DataSources.Add(dataSource); 
} 
  1. 更新報告中的數據源的.xsd。從服務器資源管理器拖動SP。
相關問題