Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Chart
Home | Forums | Videos | Photos | Blogs | Beginners
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Crystal Reports » Programming crystal report with ASP.Net 2.0 (VB) , Oracle

Programming crystal report with ASP.Net 2.0 (VB) , Oracle


I searched a lot for this program. Atlast I tried these code and made it working.

Total page views :  31710
Total downloads : 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Become a Sponsor

Introduction

The source code in this article has been developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows 2003 Server with Oracle 11i. I used the same version of Crystal Reports which comes with Visual Studio 2005 Professional Edition. But there is no problem for design the reports with Business Objects Crystal Reports 11.

Creating an ASP.Net 2.0 Web Site Project

  • Create a new Website

    ASP.Net Website
    File System
    Language VBScript

Select path and give a name to your project (Sample web). Now we have to mention the connection string. Open the Web.Config file from your SolutionExplorer window. And find <ConnectionStrings\> under <Configuration> change it by adding your connection string.

<ConnectionStrings
>
    <add name=""[Your="" Connection="" string="" name=""] = "Provider=MSDAORA; Data Source=[your Service name];Persist Security Info=True; Password=[your password];User ID=[your user id]" Provider="" Name="System.Data.OleDb"/>
    </connectionStrings>

The Front End Design:
 
For the front end I used Macromedia Dream Weaver. After that I just copy the HTML code and paste into our website source. This is not a big issue. You can design as you like. But I found VS2005 is not good for a complex front end design.

Creating a Data Set:

Right click on the Sample Web (our website name) available in then Solution Explorer and select Add New Item.

Select Data Set and give a name to the new Data Set. Here I did not use any name, I just let it go with its default name DataSet1.

Click on Add.

Here a message will prompt for adding Application Code to your Project.

Click on Yes.

A new window will arrive; and select the connection string as we entered in web.config. Here "ConnectionStringTest" [Your Connection string name].

Click on Next

You will get a new window. Click on Advanced Options and check both check boxes.

Click Ok.

Now click on Query Builder button and select the Table you need. Here I selected

Daily Balances.

Check the field that we need Execute Query. Now you will get something like following.

Click OK then click Next and then Finish.

Now you can see one DataSet1.xsd came under the Application Code.

By this we created one data set. And if you need you can add more tables into your DataSet1.xsd, by Adding Table Adapter.
Open the DataSet1.xsd, Right click on any where n the body, Add -> Table Adapter.

Adding Crystal Reports to the Website:

Right click on the Sample Web (our website name) available in the Solution Explorer and select Add New Item. Now select Crystal Reports, name it as Daily.rpt

New window will appear:

  • Select using Report wizard
  • Standard

Click on OK.

Another window will arrive for specifying data source to you report. Here under the Project Data Source expand the ADO.Net Data Set.
Select the Table.

Click on the next button and then finish.

A report Designer will appear. Design the report. Save.
Here I am using one parameter. For creating one parameter object in the Report,
In the Field Explorer box, Right click on Parameter Fields -> New
I gave a name Dtes type as String

Click OK

Save the Report.

Adding a Crystal Report Viewer in our website:

Open the Default.Aspx [or your form] in Design viewInsert the following controls,

One Label: Change its Text Property to Enter Date
One Text box: Change its Text Property to Seven Button controls:

ID  Text  Usage
Btn_Print Print Report  For taking printouts. For this I just export our report to PDF and take a printout from there.
Btn_toXL Export to Excel  For exporting to MS Excel.
Btn_Prvw Preview  For Viewing the report in the same page. For this we need four more buttons to navigate through the report.
Btn_FIrst  |< For showing the first page of the Report
Btn_Prv For showing the previous page of the Report
Btn_next For showing the next page of the Report
Btn_FIrst  >| For showing the last page of the Report

One Crystal Reports Viewer control from the Smart Task Window uncheck all the items excepts Enable Report View.

Coding:

Imports CrystalDecisions.Shared

Imports CrystalDecisions.CrystalReports.Engine

Imports System.Configuration

Imports System.Web
Imports System.Data.OleDb

First on Preview Button click.

Dim thisConnectionString As String = ConfigurationManager.ConnectionStrings("ConnectionStringTest").ConnectionString

Dim myConn As OleDbConnection = New OleDbConnection(thisConnectionString)

Dim MyCommand As New OleDbCommand()

MyCommand.Connection = myConn

MyCommand.CommandText = "Select CLIENTID,upper(CLIENTNAME)as CLIENTNAME,BALAMT,BALDATE From ALPHA_CLIENT_DAILYBALANCES WHERE (to_char(BALDATE,'dd/mm/yyyy'))=" & TextBox1.Text & ""

MyCommand.CommandType = Data.CommandType.Text

Dim myDa As New OleDbDataAdapter

myDa.SelectCommand = MyCommand

Dim myDS As New DataSet1()

myDa.Fill(myDS, "DAILYBALANCES")

Dim Rpt As New ReportDocument 

Rpt.Load(Server.MapPath("Daily.rpt"))

setting Parameter to report
Dim myparams As New ParameterFields

Dim myparam As New ParameterField

Dim mydiscvalue As New ParameterDiscreteValue

myparam.ParameterFieldName = "Dtes" Dtes, the parameter name that we created in the report
mydiscvalue.Value = TextBox1.Text

myparam.CurrentValues.Add(mydiscvalue)

myparams.Add(myparam)

CrystalReportViewer1.ParameterFieldInfo = myparams

Rpt.SetDataSource(myDS)

Rpt.PrintOptions.PaperOrientation = PaperOrientation.Portrait

Rpt.PrintOptions.PaperSize = PaperSize.PaperA4

Me.CrystalReportViewer1.ReportSource = Rpt

Navigation

Btn_first_Click

      PrintDailyBalance() I made one procedure viz PrintDailyBalance, in that I made the above code

      Me.CrystalReportViewer1.ShowFirstPage()Now we finished coding of four buttons. When we click on the preview button the report will display on the same page.

Btn_prev_Click

      PrintDailyBalance()

      Me.CrystalReportViewer1.ShowPreviousPage()

Btn_next_Click

      PrintDailyBalance()

      Me.CrystalReportViewer1.ShownextPage()

Btn_last_ClickA

      PrintDailyBalance()

      Me.CrystalReportViewer1.ShowLastPage()

Print Report

Before we go into these Print or Export button; right click on our Sample Web available in the Solution Explore -> Select New Folder.

Name that folder to Export. 

PrintDailyBalance()
Rpt.SetParameterValue("Dtes", TextBox1.Text) Setting up the parameter
Rpt.ExportToDisk(ExportFormatType.PortableDocFormat,
Server.MapPath("~/Export/Daily.pdf")

This will export our report into daily.pdf in the Export folder.

Response.Redirect("~/Export/ Daily.pdf ")

The above code s used to display the report at the same time when the user clicks on Print. 

If you want to print directly you can use the following code
 
PrintDailyBalance()
Rpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape
Rpt.PrintOptions.PaperSize = PaperSize.PaperA4
Rpt.PrintToPrinter(1, False, 0, 0)

It will print all pages , you can change last two vaue for start page and end page. If you vant to print only 1 page just give 1,1 instaed 0,0

But this can not show any printer dialog. Thats why I used with pdf. 
 
Export to Excel

PrintDailyBalance()
Rpt.SetParameterValue("Dtes", TextBox1.Text)
Rpt.ExportToDisk(ExportFormatType.Excel, Server.MapPath("~/Export/Daily.xls")
Response.Redirect("~/Export/ Daily.xls")
 
Now you can test your website.
Right click on Default.aspx -> Select View n Browser
Give the date in the Text box like dd/mm/yyyy -> click on Preview / Print Report / Export to Excel Button.

Publishing our website using web set up programme.
Copy CrystalReportsRedist2005_x86.msm to the \Program Files\Common Files\Merge Modules folder.
You can download this msm file from
www.businesobjects.com. And download cr_net_2005_mergemodules_mlb_x86.zip.

Start Visual Studio.

In the File menu, select New -> Project.
In the New Project dialog box, select a Web Setup Project or a Web Setup Project.
In the Solution Explorer, select your setup project, right-click, and select Add -> Merge Module from the pop-up menus:

Add CrystalReportsRedist2005_x86.msm to your project:

Note that Microsoft_VC80_ATL_x86.msm and policy_8_0_Microsoft_VC80_ATL_x86.msm will be automatically included when you add CrystalReportsRedist2005_x86.msm to your project:

Next we have to copy our website components into this setup file.

Open the folder, D:\Abie\TestingReports\SampleWeb (externally)

Copy all the files and Come back to new set up programme -> click on the Web Application Folder now in the centre of the screen you can see one Bin folder.  Just paste our file into this Web Application Folder.

A message will prompt select Yes or No

Go to -> Build -> Build Web Setup.

Now go to the directory where the web setup is file is created.

Find debug folder. In that you can see one websetup1.msi file and setup.exe. If you want to install just run the msi file.


Login to add your contents and source code to this article
 About the author
 
Abie Jose
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
SQL and .NET performance profiling in one place
Investigate SQL and .NET code side-by-side with ANTS Performance Profiler 6, so you can see which is causing the problem without switching tools.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
60 FREE UI Controls from DevExpress
Register for your FREE copy on over 60 free presentation controls from DevExpress - Absolutely Free-of-Charge without any royalties or distribution costs. Visit Devexpress.com/60 today. Free controls include advanced lists box, dropdown calendar, rich text edit, spin edit, tab control and so much more!

DevExpress engineers feature rich presentation controls and reporting tools for WinForms, ASP.NET, WPF, and Silverlight. Our technologies help you build your best, see complex software with greater clarity and deliver compelling business solutions for Windows and the web in the shortest possible time.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Visualize your workspace with new multiple monitor support, powerful Web development, new SharePoint support with tons of templates and Web parts, and more accurate targeting of any version of the .NET Framework. Get set to unleash your creativity.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
Read the Top 10 Books for Microsoft Developers, 15 Days FREE
Read the Top 10 Books for Microsoft Developers, 15 Days FREE
Try Safari Books Online - 15 Days FREE + 15% Off for 1 Year
Try Safari Books Online - 15 Days FREE + 15% Off for 1 Year
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Chart
Become a Sponsor
 Comments
sorry by Abie On December 19, 2009
i'm sorry .. i was not here for a while.. :(.. so that i couldn't reply for the comments
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2010.8.14
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.