Skip to main content

How to Print Using Crystal Reports


This tutorial is part of Database Programming Made Easy Series.

How to Print Using Crystal Reports

Somebody is asking if I can add sample on how to print a report. So here it is. I just tweak some little changes from our previous tutorial on Windows Forms – CheckBox Control.

I did not test this from other computer so if you encounter problem on the database location just change the report data source to the directory where you save this files.

Previous: Windows Forms - TreeView Control


Submitted byAnonymous (not verified)on Sun, 07/12/2009 - 13:42

Hi, i'm eva, from Bicol..I have a senior project "enrollment system". Is there a code needed for me to connect Oracle to just found a code for the connection of MySql and Can you help me create an admin module?...please???tnx in advance. this is my email add:[email protected]
Submitted byadminon Sun, 07/12/2009 - 18:00

I don't use oracle but all you need is to define that connection string for oracle and you're done. What kind of admin module?

but are you using don't know how make an admin..if not,can you help me in the print module?Like for the enrollment, my project should generate an assessment that contains the subjects and payment info.....

Hi sir, just wnt to ask f you know how to retrieve data from sql using label in tnx in advance...

I am using c# vs 2008 and Crystal Reports. In the preview there is no problem, but then when I run the program, I can't see the report because it ask for login. I don't have user and password. I have been searching for a long, but I coudn't find anything. my mail is [email protected] Thanks for any help Florencia

Hi, It is likely the username and pwd of your sql server needs to be provied to view your report. In the codeview you can set the databaselogon details which will bypass the logon page and displays the report directly.


MyCrReport crReportObj = new MyCrReport();
crReportObj.SetDatabaseLogon("sa", "sa", "ADPL-BLR119", "northwind");

CrystalReportViewer1.ReportSource = crReportObj;

Hope this may fix your problem.


hi, just want to ask sir if you know how to convert the string to a date.i have 3 comboBox for Day,Month, and Year.It is for birthdate and the data type is date..but i'm having hard time in vb..please help me..tnx po
Submitted byoVer_s0uLon Mon, 07/20/2009 - 09:37

Hi Good morning Sir! Uhmm. just wanna ask if you can create a simple date range say for example 2 textboxes start date and end date or even datepicker will do. Only the results will be print not all the data in the database. Thank you Sir
Submitted byAnonymous (not verified)on Tue, 07/21/2009 - 22:49

I have been try for days to load mysql field data onto a crystal report using on vs 2008 but to no avail. I keep getting the report with just the field headings but no field data at runtime. Upon previewing (not at runtime) I get some unknown data showing under my field headings. I have tried almost all the posts on the internet. What do I do now? This is my code: Imports CrystalDecisions.CrystalReports.Engine Imports System.Data.Odbc Imports MySql.Data.MySqlClient Public Class reporter 'Dim custReport As CrystalReport1 Dim myReport As New ReportDocument Dim myData As New DataSet1 Dim conn As New MySqlConnection Dim cmd As New MySqlCommand Dim myAdapter As New MySqlDataAdapter Private Sub reporter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load conn.ConnectionString = "server=localhost;uid=root; pwd=; database=boutique" Try conn.Open() cmd.CommandText = "Select CatName As Category, Quantity from ttbcategory" cmd.Connection = conn myAdapter.SelectCommand = cmd myAdapter.Fill(myData) myReport.Load("C:\Users\Shengbelen\Documents\Visual Studio 2008\Projects\WindowsApplication1\WindowsApplication1\CrystalReport2.rpt") myReport.SetDataSource(myData) CReportViewer.ReportSource = myReport Catch ex As Exception MessageBox.Show(ex.Message, "Report could not be created", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub End Class The above code is for my form with the crystalReportViewer The following code is for my print command. Private Sub PrintCtrlPToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintCtrlPToolStripMenuItem.Click reporter.ShowDialog() End Sub Please help Eric
Submitted byadminon Wed, 07/22/2009 - 14:41

In reply to by Anonymous (not verified)

Did you get any data when you preview your report using VB Editor at design time?
Submitted byAnonymous (not verified)on Tue, 08/04/2009 - 07:40

Hello, Can the solution be implemented to print from a form or menu in VB6 with CR9?

hi, just want to ask if you know how to get other data from a table.Example, when i click a value from a combo box it should automatically output the other data like the values in the combo box are subject codes,if i choose 1 subject it should output the subject title,units,..etc.. tnx
Submitted byadminon Fri, 08/07/2009 - 08:30

In reply to by Anonymous (not verified)

Your question seems not clear. Do you mean a one-to-many relationship? Like after selecting a value from a combobox another data will appear in the datagrid?
Submitted byAnonymous (not verified)on Wed, 08/05/2009 - 14:45

i have crystal report and DataSet1.xsd doc i want to acces data in crystal report regard who user login but and also i take three diff adapter in xsd file with scaler vaiable of userID but it not function please help me.
Submitted byAnonymous (not verified)on Thu, 08/06/2009 - 18:52

How to use the crystal report in C# Visual studio 2008 express edition,express edition does not support crystal report,is there any way to generate the report in express edition
Submitted byAnonymous (not verified)on Sat, 08/22/2009 - 11:07

i downloaded your code but when i try to run your program it runs but when i tried to do print it ask me about the password you enter in your sql connection. can you please send me your password, for me to be able to view your sample crystal report. thanks in advance. well[email protected]
Submitted byAnonymous (not verified)on Wed, 09/23/2009 - 21:44

Qry = "SELECT code,name,amount FROM balance3" Set Rs2 = New ADODB.Recordset Rs2.CursorLocation = adUseClient Rs2.Open Qry, db, adOpenDynamic, adLockOptimistic If Rs2.RecordCount > 0 Then Set DataGrid3.DataSource = Rs2 --------- how to get sum of datagrid pls send me code [email protected]
Submitted byAnonymous (not verified)on Wed, 07/14/2010 - 12:58

In reply to by Anonymous (not verified)

Submitted byAnonymous (not verified)on Tue, 09/29/2009 - 22:45

i want to print bill for a specific record using crystal reports. i'm using i'm beginner n dont know how to do it . plz help me to solve this problem.
Submitted byadminon Wed, 09/30/2009 - 09:21

In reply to by Anonymous (not verified)

Please read and download the source code above.
Submitted byAnonymous (not verified)on Thu, 10/01/2009 - 14:11

hi admin. i'm so impressed of your skills.. you made me realize that programming field is easy..:) im still a novice using VB and im starting to read about PHP and MySQl.. hope you can be my 'teacher' on this field.. thanks. more power.:D
Submitted byPrineon Tue, 10/27/2009 - 22:06

How do you make report to print only a row of data? And not the entire data on the database
Submitted byAnonymous (not verified)on Thu, 10/29/2009 - 16:54

if you can please put c# code i don't realize vb my mail [email protected]
Submitted byAnonymous (not verified)on Mon, 12/14/2009 - 20:14

sir i need crystal report with (useing 2 table one master having address of party and 2 is transtaion table i want to gv billno from trasation table i need its print but address of party is with first table(master) will u help me both table shoud be in sql server
Submitted byAnonymous (not verified)on Mon, 01/04/2010 - 16:51

can i use crystal report in PHP system??i'm now doing e-timesheet system using,now,i need to do a report from that,can crystal report solve it??or i need another method??
Submitted byadminon Tue, 01/05/2010 - 00:04

In reply to by Anonymous (not verified)

Yes you can as long as you know the method. For your reference please read this: I always use pdf as a reporting tool for my PHP script so I cannot really give you an idea on how to do this.
Submitted byAnonymous (not verified)on Tue, 01/12/2010 - 10:34

is it possible to print unlimited data using crystal report? kasi ang pwede lng iprint during run time is
Submitted byAnonymous (not verified)on Thu, 01/21/2010 - 15:13

sir i have to show listbox items in crystal reports with their respective data stored in their database? ex: listbox items contain only name of the student while printing i have to show their stream class & rollno in the crystal reports... please help me sir!!!
Submitted byAnonymous (not verified)on Mon, 02/01/2010 - 23:04

Submitted byAnonymous (not verified)on Sun, 02/14/2010 - 17:25

what if I am using sql database not access or any dataset how do I print crystal report? pls give me the codes...
Submitted byAnonymous (not verified)on Wed, 04/21/2010 - 14:42

how to connect several mdb databases for one crystal report at runtime in C# coding give some sample code
Submitted byAnonymous (not verified)on Wed, 04/21/2010 - 15:25

admin. i tried ur code but when i change the path of the datbase(i transfered to drive C) i got an error stating that it was an invalid path. how was that? i want a report using programatically(using sql,select statement just like in vb 6.0) w/o using any dataset. Help Please. Crystal report or RDLC for instance: I design the report (2 txtboxes/field) then i will select a data(Select * from table where ID = 'values') then what i want is that fill the two txboxes/field in the crystal report with the requested data(base on the request(select statement)) NEED IT! Tnx sir!
Submitted byAnonymous (not verified)on Thu, 04/22/2010 - 18:23

I want to print Barcode report accocrding to quantity which is sale to a customer. the barcode print in many times ,as the quantity of product, how to do it by coding send me on [email protected]
Submitted byAnonymous (not verified)on Mon, 04/26/2010 - 16:57

i have five tab page and inside of it there are many textbox that is linked into a database using access.....plz help sorry for the english
Submitted byAnonymous (not verified)on Tue, 05/04/2010 - 10:46

Hi Jaypabs. I was checking your code. I really need you help me with a sample. If I have not included my *.mdb file in my project ¿how can I change the pathfile where the program is deployed? ¿Could you add this code in your example ? I'm using 2008 and access 2007. I will apreciate your help. [email protected]
Submitted byAnonymous (not verified)on Mon, 09/20/2010 - 18:22

sir, i need the code to transfre textbox data to crystal report so sir if you have a code than sir please send it in my email id [email protected]

Add new comment