Print automaticly serverReport

Mohamed GADER 96 Reputation points
2021-10-05T17:04:37.617+00:00

Hello
I have à winform with reportviwer control
I load server report in this control
I want to print it after loading report
Reportviewer1.refresh();
Thank you verry match.

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,798 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,568 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,571 Reputation points
    2021-10-06T03:07:35.357+00:00

    May I know where you are stuck now?

    Do you not know how to load the data using the report viewer, or how to print it after loading?

    In the first case, you can follow the steps below:

    1. Right click on the item => Add=> New Item => Report/Report Wizard.
      In my memory, this step before will only produce a blank Report, but now it includes all the steps to generate a DataSet to connect to the database.
      I'm not sure if my usage is wrong. The table produced in this way seems to have to include calculations. If we just want to display the current data, then we can delete the table produced in this step and add it by ourselves using the steps below.
    2. Add a DataSet. 137954-11.png
    3. Add a table and add the required columns. 137900-12.png 137983-13.png
    4. Add Report Viewer to winform and bind the report we added as a data source.

    If it is the second case, then we can use the while loop in the Task to determine the reportViewer1.CurrentStatus.CanPrint property.

            private void Form1_Load(object sender, EventArgs e)  
            {  
                this.ScoreTableTableAdapter.Fill(this.TestDataSet.ScoreTable);  
                this.reportViewer1.RefreshReport();  
      
                Task.Run(() =>  
                {  
                    while (true)  
                    {  
                        if (reportViewer1.CurrentStatus.CanPrint)  
                        {  
                            this.Invoke(new MethodInvoker(delegate  
                            {  
                                this.reportViewer1.PrintDialog();  
                            }));  
                            break;  
                        }  
                    }  
                });  
            }  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.