Hướng dẫn add report viewer cho visual studio

một bảng connect hiện ra, ở phần server name các bạn chọn server của các bạn, mình thì để dấu . sau đó chọn CSDL bạn muốn tạo report

Hướng dẫn add report viewer cho visual studio

sau đó các bạn chọn table mà muốn tạo report, bảng đó sẽ xuất hiện trong dataset

Hướng dẫn add report viewer cho visual studio

các bạn save lại nhé, sau đó quay lại form1, chọn phần design report

Hướng dẫn add report viewer cho visual studio

một bảng xuất hiện

Hướng dẫn add report viewer cho visual studio

các bạn chọn next nhé, cái náy chắc đơn giản

Hướng dẫn add report viewer cho visual studio
, sau đó finish thôi

Hướng dẫn add report viewer cho visual studio

các bạn có thể định dạng lại cho ngày tháng năm bằng cách chọn property của field (của mình là ngày sinh) > format và chọn định dạng, nếu muốn đặt tháng thì các bạn viết MM nhé, viết mm là ra minute đấy, chú ý

Hướng dẫn add report viewer cho visual studio

sau đó quay lại form1 và làm theo hình nha

Hướng dẫn add report viewer cho visual studio

vậy là hoàn tất rồi

Hướng dẫn add report viewer cho visual studio

đầu tiên các bạn vào trong dataset hồi này nhé ở dòng cuối cùng chọn properties để thay đổi câu lệnh sql tí

Hướng dẫn add report viewer cho visual studio

ở đây mình thêm mệnh đề WHERE vào WHERE Ten_sinh_vien = @TenSV Ten_sinh_vien là field trong database còn @TenSV là đối số truyền vào, > finish đi

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

Khi bạn lập trình Winform 2013 Thì Control Report View có sẵn, nhưng khi làm trên Visual Studio 2019, Control Report view này đã bị Microsoft gỡ bỏ 1 cách không vui vẻ.Sau đây Web Thăng Long hướng dẫn bạn đưa control Report View trở lại Visual Studio 2019 để xài nhé.

Add Thư viện Microsoft.ReportViewer.WinForms vào trong Project

Đã xem 1 số hướng dẫn trên mạng vẫn không được với lỗi thông báo ngớ ngẩn thế này:

Hướng dẫn add report viewer cho visual studio

Về cơ bản thì nó báo thiếu thư viện Microsoft.ReportViewer.WinForms.dll nên chạy đếch được, sau 1 lúc loay hoay tìm trên mạng cách xử lý lỗi trên thì thấy cách fix lỗi chạy được nhất là add dll vào trong propject theo cách sau:

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Integrate Reporting Services Using the Report Viewer Controls - Get Started

  • Article
  • 03/22/2023

In this article

The Report Viewer controls can be used to integrate Reporting Services RDL reports into WebForms and WinForms apps. For detailed information about recent updates see the changelog.

Add the Report Viewer control to a new web project

  1. Create a new ASP.NET Empty Web Site or open an existing ASP.NET project. You can use .NET Framework 4.6 or any newer version.
    Hướng dẫn add report viewer cho visual studio
  2. Install the Report Viewer control NuGet package via the NuGet package manager console.

    Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms

  3. Add a new .aspx page to the project and register the Report Viewer control assembly for use within the page.

    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

  4. Add a ScriptManagerControl to the page.
  5. Add the Report Viewer control to the page. The snippet below can be updated to reference a report hosted on a remote report server.

The final page should look like the following.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Sample" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>



     
    


    

Update an existing project to use the Report Viewer control

Make sure to update any assembly references to version 15.0.0.0, including the project's web.config and all .aspx pages that reference the viewer control.

Sample web.config changes




  
    
      
        
        
        
        
        
        
        
        
      
      
        
        
      
    
    
    
      
      
    
  
  
    
    
    
      
      
    
  

Sample .aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="SampleAspx" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

Add the Report Viewer control to a new Windows Forms project

  1. Create a new Windows Forms Application or open an existing project. You can use .NET Framework 4.6 or any newer version.
    Hướng dẫn add report viewer cho visual studio
  2. Install the Report Viewer control NuGet package via the NuGet package manager console.

    Install-Package Microsoft.ReportingServices.ReportViewerControl.WinForms

  3. Add a new control from code or .

    private Microsoft.Reporting.WinForms.ReportViewer reportViewer1; private void InitializeComponent() {

    this.reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();  
    this.SuspendLayout();  
    //  
    // reportViewer1  
    //  
    this.reportViewer1.Location = new System.Drawing.Point(168, 132);  
    this.reportViewer1.Name = "reportViewer1";  
    this.reportViewer1.ServerReport.BearerToken = null;  
    this.reportViewer1.Size = new System.Drawing.Size(396, 246);  
    this.reportViewer1.TabIndex = 0;  
    //  
    // Form1  
    //  
    this.Controls.Add(this.reportViewer1);  
    
    }

How to set 100% height on the Report Viewer control

If setting the height of the viewer control to 100% the parent element is required to have a defined height, or all ancestors are required to have percentage heights.

Set the height of all the ancestors to 100%




    
   

    

Set the parent's height attribute

For more information about viewport percentage lengths, see .






    

The Report Viewer Control is now shipped as a NuGet package and no longer shows in the Visual Studio toolbox by default. You can add the control to the toolbox manually.

  1. Install the NuGet package for either the WinForms or WebForms as mentioned above.
  2. Remove the Report Viewer Control that is listed in the toolbox.
    Hướng dẫn add report viewer cho visual studio
  3. Right-click in anywhere in the toolbox and then select Choose Items....
    Hướng dẫn add report viewer cho visual studio
  4. On the .NET Framework Components, select Browse.
    Hướng dẫn add report viewer cho visual studio
  5. Select the Microsoft.ReportViewer.WinForms.dll or Microsoft.ReportViewer.WebForms.dll from the NuGet package you installed.

    Note The NuGet package will be installed in the solution directory of your project. The path to the dll will be similar to the following:

    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

    1 or

    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

    2.
  6. The new control should display within the toolbox. You can then move it to another tab within the toolbox if you wish.
    Hướng dẫn add report viewer cho visual studio

Common issues

The viewer control is designed for modern browsers. The control may not work as expected if the browser renders the page using IE compatibility mode. Intranet sites may require a meta tag to override default browser behavior.

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

0

NuGet.org pages

Here are links to articles on the NuGet.org site about the WebForm and WinForm versions of the Report Viewer control: