Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Datagridview VB.NET填充ReportViewer_Vb.net_Datagridview_Reportviewer - Fatal编程技术网

如何从Datagridview VB.NET填充ReportViewer

如何从Datagridview VB.NET填充ReportViewer,vb.net,datagridview,reportviewer,Vb.net,Datagridview,Reportviewer,换句话说,如何将DataGridView的数据源设置为ReportViewer的源 我使用SQL中的表填充名为DGVData的datagridview: SqlCmd = New SqlCommand(Query, SQLCon) SQLDA = New SqlDataAdapter(SqlCmd) SQLDataset = New DataSet SQLDA.Fill(SQLDataset) Form2.DGVData.DataSource = SQLDataset.Tables(0) Da

换句话说,如何将
DataGridView
的数据源设置为
ReportViewer
的源

我使用SQL中的表填充名为DGVData的datagridview:

SqlCmd = New SqlCommand(Query, SQLCon)
SQLDA = New SqlDataAdapter(SqlCmd)
SQLDataset = New DataSet
SQLDA.Fill(SQLDataset)
Form2.DGVData.DataSource = SQLDataset.Tables(0)
Datagridview工作正常,但当我尝试使用下面的代码填充
ReportViewer
时,它返回一个错误

无法将“System.Data.DataTable”类型的对象强制转换为“Microsoft.Reporting.WinForms.ReportDataSource”类型。


提前谢谢。

将您的
SQLDataset.Tables(0)
传递给mainReport并将其设置为DataSource您的意思是像mainReport.LocalReport.DataSources.Add(SQL.SQLDataset.Tables(0))一样,它说“类型值”System.Data.DataTable不能转换为“Microsoft.Reporting.WinForms.ReportDataSource”。请参见
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    MainReport.LocalReport.DataSources.Add(DGVData.DataSource)
    MainReport.LocalReport.Refresh()
End Sub