65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 LINQ 和 ASP.NET 的 Microsoft SQL Server Reporting Services (SSRS)

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.20/5 (5投票s)

2010年5月13日

CPOL
viewsIcon

41027

我第一个使用 Microsoft SQL Server 2008 Reporting Services (SSRS) 的例子

引言

我希望在这里帮助那些刚开始使用 .NET 3.5 和 SSRS 的人。 如果您按照以下步骤操作,您将能够创建您的第一个报表。

背景

我在此示例中使用了 VS 2008 和 SQL 2005 以及 Linq。

步骤

  1. 创建一个表,例如 StudentInfo

  2. 向您的表中添加一些数据

    Report2.jpg

  3. 使用 VS 2008 创建一个新项目

    Report3.jpg

  4. 向您的项目添加新项目

    Report4.jpg

  5. 从项目列表中选择报表

    Report5.jpg

  6. 输入您的报表名称

    现在您需要做的就是将 ReportViewer 拖到您的 aspx 页面上

    Report6.jpg

    选择 Reportviewerdatasource

    Report7.jpg

您的 HTML 页面将如下所示

Report8.jpg

以下是一些您需要执行的步骤

向您的项目添加一个 dataset ,并向 dataset 添加一个 datatable 。 我使用 MyDataset DataTable StudentInfoDataTable。 这是您需要复制到页面加载事件中的代码

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MyDataClassesDataContext db = new MyDataClassesDataContext();
IQueryable<StudentInfo> data = from d in db.StudentInfos select d;
ReportDataSource rds = new ReportDataSource("MyDataSet_StudentInfoDataTable", data);
ReportViewer1.LocalReport.DataSources.Add(rds);
}
}
© . All rights reserved.