Question

Passing parameter into Crystal Report

Asked by: tlfeet

I am new to Crystal Report.  I am using VB.NET and Crystal Report 8.5

I created a report, when connecting to the database, I only see tables but not store procedures, I have all the access rights but the store procedures not show up in the wizards.  Any way, I just select the table name Fabric and field names.  
I want to display only one record, I look at show sql statement:
 SELECT "Fabric"."FabricID", "Fabric"."CustomerID", "Fabric"."FabricCode", "Fabric"."SMProjectName", "Fabric"."SMPlanID", "Fabric"."SMRoomName", "Fabric"."SupplierName", "Fabric"."PatternAndColor", "Fabric"."QtyReceived", "Fabric"."DocumentID"
 FROM   "enterprise"."dbo"."Fabric" "Fabric"
 WHERE  "Fabric"."FabricID"=222049

The FabricID need to be a parameter field.  So I insert a "Record Selection Formula" and name the field "fabricParam" and it formula was {Fabric.FabricID} = 222049.

My Webform1.aspx.vb code is:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer

    'Dim crpt As CrystalReport1
    Dim crpt As crFabricLabel

    Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
    Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo

    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        'crpt = New CrystalReport1
        crpt = New crFabricLabel
        For Each myTable In crpt.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.Password = "pwd"
            myLogin.ConnectionInfo.UserID = "user"
            myTable.ApplyLogOnInfo(myLogin)
        Next

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition

        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        'Set discrete value
        crParameterDiscreteValue.Value = CInt("1000002442")

        'Access first parameter field definition
        crParameterFieldDefinitions = crpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("fabricParam")

        ' Add parameter value
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Add(crParameterDiscreteValue)

        ' Apply the current value to the parameter definition
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

        CrystalReportViewer1.ReportSource = crpt

    End Sub

End Class

When run the web form I got this error:

Exception Details: CrystalDecisions.CrystalReports.Engine.InvalidArgumentException: Invalid field name.

Source Error:


Line 51:         'Access first parameter field definition
Line 52:         crParameterFieldDefinitions = crpt.DataDefinition.ParameterFields
Line 53:         crParameterFieldDefinition = crParameterFieldDefinitions.Item("fabricParam")
Line 54:
Line 55:         ' Add parameter value
 
So can anybody help me how to put in a parameter field into the Crystal report form so that {Fabric.FabricID} = some variable instead of a pre-defined number.
The error message tell me that I have not define fabricParam anywhere in the form but It is there.
I will get to how to get store procedure, but that will be next.

Many thanks

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-08-06 at 16:25:50ID21085368
Tags

crystal

,

report

,

parameter

Topic

Crystal Reports Software

Participating Experts
4
Points
500
Comments
14

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. assign parameters in crystal report VB.net
    how do i use date parameters in crystal report VB.net ? i am new to this so i need step by step instructions . kindly assist
  2. Crystal Reports in VB.Net
    Hi I am looking for information on using Stored Proceudres with Crystal Reports in VB.Net Is there any step by step guide I can use to show me how to do this I have created the stored procedure, linked it to my crystal report the problem Im having is passing the parameters...
  3. vb.net  and crystal reports
    Hi fellows. I need to create a report with in vb.NET enviroment using stored procedure . i am using vb.net 2003. i did reporting base don Sp but in Crystal report design enviroment . \ but this time i need to create report with in .net enviroment. regards bilal
  4. Passing VB.NET variable to Crystal Report
    I have a vb.net form in VS 2008. The form contains a combobox listing locations, two textboxes to specify a date range, a ReportViewer control and a button to run the report based on the criteria inputted. All I want to do is pass the location and date range criteria to the...
  5. how to group in a crystal report based on formula using vb…
    how to group in a crystal report based on formula using vb.net
  6. selection formula and parameter to create Crystal Report
    Hello, I have the following situation. I am developing a web application to create Crystal Reports using CrystalReportViewer control. Platform: ASP.NET (2.0), Code Behind: VB.NET, Database: Oracle 10G In the form, I enter the search criteria and create a selection formula as...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: frodomanPosted on 2004-08-06 at 18:19:31ID: 11740981

It sounds like you've forgotten to create the parameter in your report.  In the crystal designer you need to create a parameter named fabricParam of type number.  Then you want to set your select expert to be

   {Fabric.FabricID} = {?fabricParam}

Now you can pass the parameter from your application to Crystal and it should work as you want.

By the way, check your database options for the stored procedures.  By default you see only tables but you can check the option to see stored procedures and views also if desired.

HTH

frodoman

 

by: EwaldLPosted on 2004-08-07 at 00:22:34ID: 11741963

follow frodoman's steps and it should work.

this code may also help to keep your syntax neat. parameter passing was made possible with a single line of code, ie
rpt.SetParameterValue("{?fabricParam}", 222049)

 

by: tlfeetPosted on 2004-08-09 at 12:03:24ID: 11756098

Thanks for the tips.

I bought the Crystal book today, and on the session adding a parameter.  It said to add a parameter to a report select insert, field object.

However, when I right click on the crFabricLabel form designer, the drop down list insert field was gray out.  Also, I go back to add/remove database to bring up the database wizards, I don't see any places for store procedure, it only give me tables and views, and don't see any check box.

So I think that I only have a basic Crystal Report engine. I installed Visual studio.net on my PC and using my local IIS 5.1, do we need addition installation for Crystal Report or down load from Microsoft any addition components?  

I create this Crystal Report in ASP.NET by right click the project name in solution explorer and click add/new item. Then I choose Crystal Report.

By the way, we have MSDN version.  Do we have separate Crystal DVD provided w/ MSDN DVD(s)? I haven't seen the whole MSDN diskettes yet. I worked for a very small company and a silly owner who want to take control of everything but very silly w/ hi-tech.  So every time, if I mumbling “I am stupid”, then I correct myself right away, there is one even more stupid than you.

 

by: frodomanPosted on 2004-08-09 at 12:14:07ID: 11756216

You indicated in your first posting that you're using CR8.5.  It sounds like you're actually using the version that comes with Visual Studio which is a stripped down version of CR9 - is that correct?

Within VS to insert a parameter you need to look at the "Field Explorer" window, rt-click on "Parameter Fields", then select "Insert".

HTH

frodoman

 

by: frodomanPosted on 2004-08-09 at 12:18:22ID: 11756273

Also, assuming you are using the VS .net version to get stored procedures do this:

rt-click in the designer window then select: Designer -> Default Settings -> Database   then check the stored procedures option.

frodoman

 

by: frodomanPosted on 2004-08-09 at 12:18:28ID: 11756274

You indicated in your first posting that you're using CR8.5.  It sounds like you're actually using the version that comes with Visual Studio which is a stripped down version of CR9 - is that correct?

Within VS to insert a parameter you need to look at the "Field Explorer" window, rt-click on "Parameter Fields", then select "Insert".

HTH

frodoman

 

by: EwaldLPosted on 2004-08-09 at 12:21:33ID: 11756307

the field explorer can be hard to find in case it has been closed. this explains how to get it on screen
http://support.businessobjects.com/library/kbase/articles/c2010362.asp

crystal should be installed automatically with .net, by default it is selected to be installed. some lower versions of .net don't include crystal at all. not sure whiches ones have it though. if you click on "new item" you should see "crystal report", this would confirm if it has been installed correctly

 

by: frodomanPosted on 2004-08-09 at 12:30:49ID: 11756408

Crystal is included w/ all versions of Visual Studio (at least all production versions - I can't say for the beta version if that's still floating around).  If you buy a standalone (non-studio) tool such as VB.Net, C#.Net, etc. then you don't get Crystal with it.

 

by: tlfeetPosted on 2004-08-09 at 13:42:43ID: 11757064

U're right, I 've a stripped down version of Crystal Report.  Not sure what version it is, my VS is 2003.  Don't know how to tell what version of Crystal I had.

Thanks for every thing.

But I do have a question.  Do you suggest this book
Professional Crystal Reports for Visual Studio.NET, 2nd Edition
By David McAmis
Publisher Wrox - A Branded Imprint of Wiley

This morning I came to San Diego Tech book store to get this, however they only have 3 books display on the book sheves.  Don't want to wait for 7 - 15 shipping days, I picked up the Using Crystal Enterprise 8.5.  I have to return this book.  So I wonder it is worthed to exchange it with the above book.  This owner is very creedy, I paid out of my pocket.  I don't bother to ask him for reimbursement.

Thanks,

 

by: frodomanPosted on 2004-08-09 at 13:54:33ID: 11757203

>>> Do you suggest this book   Professional Crystal Reports for Visual Studio.NET, 2nd Edition

I haven't used that book so I can't say whether it's good or not.  What I can tell you is

a) I've personally been fairly happy w/ other Wrox books that I've bought.  Some were better than others but only one was really bad so the odds are in your favor.  Check Amazon.com for reviews though and see what other people have said about it...

b) The Crystal Enterprise 8.5 book is going to be useless to you.  Keep in mind that Crystal ENTERPRISE is not the same as Crystal REPORTS.  They're cousins and they work together but they aren't the same thing.  Also the Visual Studio version is much different than Crystal Reports 8.5.

Don't worry about the version - it's just the ".Net" version of Crystal which is an OEM version of Crystal Reports 9.  It's not too stripped down - you can still do 90% of what the standalone version can do and it's still a great tool.

It's your call on the book.  Personally I've never read a Crystal book - I picked it up by playing with it and of course w/ help from people on this site.  If you have some time to work with it and can use this site as a resource then I'd save the money - if you don't have the time for trial and error then I'd definately look for a book like the one you mention.  The .Net version is just different enough that you could get frustrated trying to learn with a "regular" Crystal book.

Good luck!

frodoman

 

by: tlfeetPosted on 2004-08-09 at 14:05:22ID: 11757306

Thanks

 

by: rhedrickPosted on 2004-10-26 at 10:59:51ID: 12413751

I used that 2nd edition book and thought it wasn't great.  It's ok if you're just starting but you can't do much with it

 

by: tlfeetPosted on 2004-10-27 at 08:26:25ID: 12423257

Thanks, I'd returned it long a go.  Any way, I did write separate windows application to run batch report because we can't not send to printer directly w/o user clicking on print under web application.

I didn't use Crystal report.

 

by: erikleeolsonPosted on 2004-11-11 at 09:10:56ID: 12556636

I'm having a similar problem, I can pass the value (incidentally, Ewaldl, your suggestion works, but the short syntax is

rpt.SetParameterValue("fabricParam", 222049)

without the curly braces or question mark)  and my sql command uses the parameters that I pass, specifically, my sql command is thus:

select * from [Runtime Library].dbo.CIFReportCommissionDuednis ('{?WebUserID}','{?WebPassword}')

however I am getting an empty recordset, as though I was passing nulls.  I placed the actual parameter values on the report and they show up as having been set properly (in my case the parameters are both "test1" which in query analyzer returns a full recordset).

Hmmmm I can't figure this one out!  Should I not be using a simply "command" data source?  


20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...