Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i am working on window form application and add Crystal Report in the project named "crystalreport1" and in the form1(window form) take CrystalReportViewer1.i want fill crystal report via programatically. by the followng way i give datatable to crystalreport. then errror araised that "REPORT HAS NO TABLES",how i can solve this problem.

What I have tried:

Dim dt As New DataTable
dt.Columns.Add("id")
dt.Columns.Add("name")
dt.Columns.Add("address")
dt.Rows.Add(1, "ali", "lhr")
dt.Rows.Add(2, "nomi", "mul")
Dim rpt As New CrystalReport1
rpt.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.Show()
Posted
Updated 31-Mar-19 22:56pm

1) Name that DataTable
2) Add it in DataSet
3) Add DataSet as a source of a crystal report
 
Share this answer
 
v2
Hi! If you are using Datagridview put this code on your print button.

Dim dt As New DataTable

       With dt
           .Columns.Add("id")
           .Columns.Add("name")
           .Columns.Add("address")
       End With


       For Each dr As DataGridViewRow In Me.dgv_list.Rows
           dt.Rows.Add(dr.Cells("id").Value, dr.Cells("name").Value, dr.Cells("address").Value)

       Next

       Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
       rptDoc = New cr_logslist
       rptDoc.SetDataSource(dt)

       frm_report_viewer.CrystalReportViewer1.ReportSource = rptDoc
       frm_report_viewer.ShowDialog()
       frm_report_viewer.Refresh()
       frm_report_viewer.Dispose()

Note: Change cr_loglist with the name of your Crystal Report file.

Hope it helps.
 
Share this answer
 
Comments
Member 14197412 1-Apr-19 5:17am    
thank you...i tried it but same error that "REPORT HAS NO TABLES"..

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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