Programmer's Corner - Visual Basic .NET Source Code Sample

Backup and Security Solutions 10% off all products with promo code: VISI-P1YR
Get the Programmer's Corner FireFox Search Plug-In

Crystal Reports Using Stored Procedure with Parameters - Visual Basic .NET

siddharth sinha

www.animon.net

         

         

Introduction:
The User sometime faces a problem to prepare Crystal Reports using Stored Procedure in .NET. Passing a parameter into a report can be difficult.


Using the code:
First, create a Stored Procedure which takes a parameter. Now use this Procedure in creating a crystal report. In VB.NET Crystal Report is built-in.

Now you have a crystal report which asks for parameter value, which should be passed by your program, Not with an input box.





//
// Any source code blocks look like this
Imports System.Data.SqlClient
Imports System.Data 
Imports System.Data.Common
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
 
Public Class Form1 Inherits System.Windows.Forms.Form

 #End Region

 Public reporttype As String
 //creating an object of the crystall report
 Public cr3 As New CrystalReport3 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 End Sub

//calling the report on keypress property
 Private Sub txtExch_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtExch.KeyPress
 If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
 e.Handled = True

//setting first parameter as the report ask for two parameter
 cr3.SetParameterValue(0, txtOrgName.Text)

//setting second parameter as the report ask for two parameter
 cr3.SetParameterValue(1, txtExch.Text)

// set the Crystal report viewer as the the cr3 ( the object of the crystal report)
 CRViewer.ReportSource = cr3

 End If 

End Sub 
 End Class 
//