Click here to Skip to main content
15,886,724 members

Convert DataGridView into Crystal Report in Code?

savedlema asked:

Open original thread
Hi friends!

I'm looking for an easy way to enable a user of my app to print the contet of a GridView.However, I think an easy way will be to convert it into a Crystal Report or pdf (many people say to pdf is terrible), so, I'd like to convert it into a Cyrstal Report (or just a report). Some people have talked about converting a GridView into a Crystal Report, but none have I seen talking about this when I generated my GridView in codes. I mean, people will talk of creating the dataset and data adapter using the GUI in VS2010, but I created mine in codes. Also, when telling the CR where to get its data, people talk about dragging the data connections (table fields etc) to the report in a GUI way, but I can't see how to do that in codes. I use codes for dataset and data adapter in my application forms, how can I code the Crystal Report?
(I develop with VB.NET, VS 2010)

VB
Public inc As Integer
    Public MaxRows As Integer
    Public con As New OleDb.OleDbConnection
    Public dbProvider As String
    Public dbSource As String
    Public ds As New DataSet
    Public da As OleDb.OleDbDataAdapter
    Dim sql As String
    Dim sqlVacation As String
    Dim sqlRadio As String

      'database

        dbProvider = "PROVIDER= Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = data/Human Resource.mdb;"

        con.ConnectionString = dbProvider & dbSource

        'Search for Department

        If rdDept.Checked = True Then

            ds.Tables.Clear()
            con.Open()
            sqlRadio = "SELECT ID,FirstName,MiddleName,Surname,Phone,Birthday,Empl_Year,Department,Residence,Status " _
            + "FROM tblDetails" _
            + " WHERE Department = '" & Trim(Me.txtSearch.Text) & "'"

            da = New OleDb.OleDbDataAdapter(sqlRadio, con)
            da.Fill(ds, "HumanResource")
            con.Close()

            'Fill the data grid
            dgv1.DataSource = ds.Tables("HumanResource")

            'If nothing was found
            If ds.Tables("HumanResource").Rows.Count = 0 Then
                MsgBox("No any record found matching your search.", vbCritical, "GreatestHR:Search Results")
             dgv1.DataSource = ds.Tables("HumanResource")
            End If


I want to enable the user to print these results by creating a Crystal Report that will get its data from this gridView, (then I can print from the CR).
I have googled for this for some day now, can someone out there please help?

Thanks in advance,
its Frank!
Tags: Visual Basic, DataGridView, CrystalReports

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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