I'm using Visual Studio 2019 to create a Windows Form app.
I am trying to implement a function that can print the contents displayed in DataGridView.

Since ActiveReports etc. are expensive, I would like to implement the printing function with Microsoft Report.
I don't know how to do it because there are few reference materials.

What i want to do
"Print the DataTable set in the DataGridView's DataSource"
I don't know how to set a DataTable to a Microsoft Report.
Thanks for your cooperation.

Corresponding source code

Using dbconnection As New SqlConnection (connection string)
Using dbcommand As SqlCommand = dbconnection .CreateCommand


dbconnection .Open ()

Using da As New SqlDataAdapter

Dim dt As New DataTable

dbcommand .CommandText = strSQL

da.SelectCommand = dbcommand

da.Fill (dt)

DataGridView1.DataSource = dt ← I want to print this DataTable

End Using

Catch ex As Exception
MessageBox.Show (ex.Message)
End Try

End Using
End Using

What I tried

I thought about it with reference to the following site
I've never used a Dataset before, and I don't know how to use it.
Is there no choice but to use a Dataset to create a Report?
Reference site

Supplementary information (FW/tool version, etc.)


Development language VB

  • Answer # 1

    I thought about it with reference to the following site, but I have never used Dataset and I do not know how to use it.

    If you don't understand even if you look at the "site below" that is explained in detail and carefully with images, it is impossible to ask a question here and get the answer you want. No further explanation is possible on such a Q&A site.

    "The following site" uses the Data Source Configuration Wizard of Visual Studio to generate and use a typed DataSet/DataTable + TableAdapter, but Windows Forms apps that use DataGridView use it normally, so "Until now, Dataset I've never used it, and I don't know how to use it. " The questioner seems to be better off studying from that point first.

    After that, please refer to the "site below" and move your own hands to write the code and actually create an application that uses ReportViewer. You should be able to easily create it with little code using the wizards in Visual Studio.

    If you have any questions or things that don't go as expected at that stage, upload your own code to explain how far you can implement it, where you are stumbling, and what you need to know to solve it. Please try to.

    The current question is the content before the round throw, and it is only subject to negative evaluation.