Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 1 datagridview and have created a crystal report too.
I have written a query on some conditions which is displaying in datagridview. so that data i want to display in crystal report for printing

i want to bind the dataset with datagridview and then display in crystal report. but the data from datagridview is not displaying in crystal report.

the code is as follows
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
       Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=record;user=sa;password=gariahat")
       Dim ds As New DataSet
       Dim dt As DataTable
       Dim cmd As New SqlCommand("select * from fullsort where return_dt is null ", cn)
       Dim da As New SqlDataAdapter(cmd)
       dt = New DataTable
       da.Fill(dt)
       FullsortDataGridView.DataSource = dt

       cn.Close()
   End Sub

   Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

       Form32.Show()

   End Sub




Imports System.Configuration
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportAppServer
Public Class Form32

    Private Sub Form32_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim crReportDocument As New cr
        Dim ds As New DataSet
        CrystalReportViewer1.ReportSource = crReportDocument
        cr1.SetDataSource(ds.Tables(0))


        Form2.DataDataGridView.DataSource = ds.Tables(0)
       
    End Sub



the last code is for crystal report coding
can anyone help me in getting solution
Posted

your New Ds Has No Data Inside it !! ( in the Crystal Report Code Part )

add this code

VB
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=record;user=sa;password=gariahat")
      Dim ds As New DataSet
      Dim dt As DataTable
      Dim cmd As New SqlCommand("select * from fullsort where return_dt is null ", cn)
      Dim da As New SqlDataAdapter(cmd)
      dt = New DataTable
      da.Fill(dt)
      FullsortDataGridView.DataSource = dt

      cn.Close()


to Actually Load the Data to The Newly Created DS :)

That's Why there is an Error and No Data Appears
 
Share this answer
 
Comments
sudeshna from bangkok 1-Oct-13 0:44am    
where will i add this code? in form32? that is crystal report viewer?
sudeshna from bangkok 1-Oct-13 0:46am    
showing error that fullsortdatagridview is not declared
Yes , to actually get Data for the Report

VB
Imports System.Configuration
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportAppServer
Public Class Form32
 
    Private Sub Form32_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Load Data
        Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial     catalog=record;user=sa;password=gariahat")
      Dim cmd As New SqlCommand("select * from fullsort where return_dt is null ", cn)
      Dim da As New SqlDataAdapter(cmd)
      dt = New DataTable
      da.Fill(dt)
      cn.Close()


        Dim crReportDocument As New cr
        CrystalReportViewer1.ReportSource = crReportDocument
        cr1.SetDataSource(dt)
 

        Form2.DataDataGridView.DataSource = dt
       
    End Sub
 
Share this answer
 
Comments
sudeshna from bangkok 1-Oct-13 0:58am    
when i am running my application and clicking on print button to display the crystal report
the following error is coming
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\win64_x64\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified.
sudeshna from bangkok 1-Oct-13 1:11am    
why this error coming?
sudeshna from bangkok 2-Oct-13 23:13pm    
Can anyone help me please. not getting the data loaded in crystal report from datagridview
sudeshna from bangkok 2-Oct-13 23:32pm    
i think my coding is wrong, because in same project my other crystal reports are working, only this report where i have written this code to extract data from datagridview and print in crystal report, this report not working
sudeshna from bangkok 2-Oct-13 23:33pm    
Can anyone help me in rectifying my error

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