Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam newer in programming i need some help I Want To Show All Rows In Datagridview in Crystal report In Case My DatagridView Has No DataSource I just add All value Manual To it After I Insert All Value I want To Click A Button To send All This Rows To Cyrstal Report iam using Visual Studio 2015 I just create New project and put Datagridview1 and CrystalReportViewer1 And this Is My Code Under Button Move To crystal

Dim crystal As New CrystalReport1
    crystal.SetDataSource(DataGridView1.DataSource)
    CrystalReportViewer1.ReportSource = crystal
    CrystalReportViewer1.Refresh()

and when i click the button i got this the report has no table Error Picture
<a href="https://i.stack.imgur.com/N9blQ.jpg"></a>
 what to do


What I have tried:

i tried this code i wrote it Help Me
Posted
Updated 7-Jun-18 0:43am

1 solution

In case when a DataGridView[^] component is not bind with some data source, a DataSource property[^] returns Nothing.

So, you need to create a data source for crystal report. See:
VB.NET
Dim dgv As DataGridView = Me.DataGridView
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(dgv.Columns.Cast(Of DataGridViewColumn)().Select(Function(x) New DataColumn(x.Name)).ToArray())
dt = dgv.Rows.Cast(Of DataGridViewRow)() _
	.Select(Function(x) _
		dt.LoadDataRow(New Object() _
		{ _
			x.Cells(0).Value, _
			x.Cells(1).Value, _
			x.Cells(2).Value _
		}, False)) _
	.CopyToDataTable()
Dim crystal As New CrystalReport1
    crystal.SetDataSource(dt)
    CrystalReportViewer1.ReportSource = crystal
    CrystalReportViewer1.Refresh()


You can achieve the same by using simple for ... next loop by columns and rows in DataGridView.
Good luck!
 
Share this answer
 
Comments
Member 11691579 7-Jun-18 9:48am    
Thank You so Much But I got this error When Iam trying To Use Your Code
http://prntscr.com/js3aih
Maciej Los 7-Jun-18 13:51pm    
I can't read in your mind or direct from your screen. You have to debug your code to find out the reason of such of bahaviour.
Member 11691579 7-Jun-18 14:24pm    
i put Your Code in
Try


Dim dgv As DataGridView = Me.DataGridView1
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(dgv.Columns.Cast(Of DataGridViewColumn)().Select(Function(x) New DataColumn(x.Name)).ToArray())
dt = dgv.Rows.Cast(Of DataGridViewRow)() _
.Select(Function(x) _
dt.LoadDataRow(New Object() _
{
x.Cells(0).Value,
x.Cells(1).Value,
x.Cells(2).Value
}, False)) _
.CopyToDataTable()
Dim crystal As New CrystalReport1
crystal.SetDataSource(dt)
CrystalReportViewer1.ReportSource = crystal
CrystalReportViewer1.Refresh()
Catch ex As Exception
MsgBox(ex.Message)
End Try

This Is the Result I got the same Error
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified.

Only Your Code make This
Could You Please make An Example For Me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900