Hướng dẫn cài đặt report asp.net

Install Microsoft RDLC Report Designer 2022 extension on Visual Studio, to add adds "Report Application" project template, and "RDLC Report" item template and the "RDLC Report Designer" to Visual Studio.

Note: If you create a "Report Application" project, since it has preinstalled Nuget package of ReportViewer, then you don't need to explicitly install the package yourself. Make sure you rebuild the project after created.

Add ReportViewr Control to toolbox of WinForms application

Install Microsoft.ReportingServices.ReportViewerControl.Winforms Nuget Package on a .NET Framework Windows Forms project, to add ReportViewer control to toolbox. .

Note: It doesn't include the RDLC report template and the report designer, so you usually need to install above VS extension as well. But you don't necessarily need to create "Report Application", a normal Windows Forms .NET Framework app, and then installing the NuGet package does the same thing as the Report Application app [without a wizard at the beginning]. Make sure you rebuild the project after you installed the package

Reporting Service Reports project template, RDL item template, and RDL report designer

Install Microsoft Reporting Services Projects 2022 which is for creating Report .rptproj projects which is for Reporting Service Reports [RDL];

Note: It doesn't add the RDLC report template or Report Application project template, or RDLC report designer, and you only want it if you want to have a report server project and deploy the project to SSRS.

.NET CORE 3.1, and .NET 5+

Above solutions works for .NET Framework projects. If you want ReportViewr for .NET 5+ , or .NET Core 3.1+ you may want to use ReportViewer Core

Bảng xuất hiện, ta có thể sử dụng connection string có sẵn hoặc tạo mới cho DataSet, Connection String này sẽ được lưu vào webconfig.

Nhấn next, ở đây ta có 3 lựa chọn để truyền dữ liệu vào DataSet

  • Sử dụng câu query bình thường.
  • Tạo mới một procedure.
  • Sử dụng procedure có sẵn.

Cách 1

: Sử dụng câu query: [Không có điều kiện where lấy tham số] Ở giao diện Choose a Command Type, nhấn next. Trong khung này ta gõ trực tiếp câu lệnh SQL

Gõ câu lệnh SQL vào khung.

Sau đó ta nhấn Query Builder để ra giao diện và nhấn Execute Query để thực thi câu query này, sau đó nhấn OK và nhấn Finnish để kết thúc:

Cách 1

: Sử dụng câu query có điều kiện Where lấy giá trị từ web [vd lấy từ query string, session]: Tương tự như bảng nhập vào câu query, ta thêm điều kiện như sau:

SELECT NHANVIENGUID, MANV, TENNHANVIEN, TUOI, EMAIL FROM NHANVIEN Where tuoi = @Tuoi

Sau đó nhấn Query Builder, giao diện xuất hiện ta nhấn execute query, một bảng nhỏ hiện ra ta nhập vào giá trị cho điều kiện where ban nãy

Cách 2: Sử dụng procedure có sẵn: Ở giao diện Adapter Configuration Wizard, mục Choose a command type, check vào Use existing stored procedure, nhấn next. Giao diện hiện ra có 4 mục chính cho procedure: insert - update - delete - select, ở đây ta chọn select:

Chọn tên procedure và nhấn finish.

3. Tạo mới 1file report [report.rdlc]:

Giao diện file report

Ở toolbox, kéo thả table vào report:

Hoặc chọn New/DataSet:

Bảng chọn DataSet xuất hiện:

Phần DataSource hiện ra ta chọn DataSet lúc trên đã tạo, [Lưu ý với phiên bản Visual 2010 thì nên tạo file DataSet không nằm trong bất kì folder nào cả, sau khi bước này thực hiện thành công thì ta có thể di chuyển file DataSet này tại nơi mình muốn. Nếu tạo trong folder con thì sẽ gặp tình trạng như hình này: //i.stack.imgur.com/yhiO0.png. Bản visual 2010 sp1 đã khắc phục được vấn đề này].

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Lesson 6: Add a ReportViewer Control to the Application

  • Bài viết
  • 03/22/2023

Trong bài viết này

After you design the child report by using the Report Wizard, your next step is to add a ReportViewer control to the website application. If you are using the ASP.NET Reports Web Site, it will have added the ReportViewer control to the default.aspx page.

To add a ReportViewer control to the application

  1. In Solution Explorer, right-click Default.aspx, and then click View Designer.
  2. If default.aspx already has the ReportViewer Control on it, skip to Step 4. Otherwise, From the AJAX Extensions group in the Toolbox window, drag a ScriptManager control to the design surface.
  3. From the Reporting group, drag a ReportViewer control to the design surface below the ScriptManager control.
  4. Open the ReportViewer Tasks window by clicking the arrow in the top right-hand corner of the ReportViewer control.
  5. In the Choose Report box, select the parent report you created. When you select a report, instances of data sources used in the report are created automatically. Code is generated to instantiate each DataTable [and its DataSet container]. An ObjectDataSource control is added to the design surface, corresponding to each data source used in the report. This data source control is configured automatically.
  6. On the Build menu, click Build website. The report is compiled and any errors such as a syntax error in a report expression appear in the Error List area. Click Error List at the bottom of the Visual Studio window to display the Error List area.

Next Task

You have successfully added a ReportViewer control to the website application. Next, you will add a drillthrough action on the parent report. See Lesson 7: Add Drillthrough Action on Parent Report.

Chủ Đề