Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pass Form Variable to Report Parameter

Posted on 2013-06-05
5
Medium Priority
?
377 Views
Last Modified: 2013-06-11
Hello experts.  

I have a crystal report built into a VB Form (Form1.cs), and I have a string defined that I need to feed to a parameter inside my CrystalReport1.cs.

In my Form1.cs, here's the code for the variable:
/********************************
        public Form1()
        {
            InitializeComponent();
            System.Security.Principal.WindowsIdentity user =
                        System.Security.Principal.WindowsIdentity.GetCurrent();

            MessageBox.Show(user.Name);
            try
            {
                ITerminalServicesManager manager = new TerminalServicesManager();
                using (ITerminalServer server = manager.GetLocalServer())
                {
                    server.Open();
                    foreach (ITerminalServicesSession session in server.GetSessions())
                    {
                        if (session.UserAccount != null && (user.Name.Split('\\')[1].ToLower() == session.UserName.ToLower()))
                        {
                            string station_id = Environment.MachineName + ":" + session.SessionId;
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);

********************************/


In my CrystalReport1.cs, the parameter section:

/*******************
     [Browsable(false)]
        [DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
        public CrystalDecisions.Shared.IParameterField Parameter_stationvariable {
            get {
                return this.DataDefinition.ParameterFields[1];
            }
        }
*******************/

I need to pass the station_id form variable to the Parameter_stationvariable.

Something like:

/**********
[Browsable(false)]
        [DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
        public CrystalDecisions.Shared.IParameterField Parameter_stationvariable {
            get {
                Private Sub ApplyTextObject(ByVal vstrTextObject As String, _
                ByVal vstrTextValue As String)
                    Try
                        CType(mrptDoc.ReportDefinition.ReportObjects(vstrTextObject), _
                        CrystalDecisions.CrystalReports.Engine.TextObject).station_id = _
                        vstrTextValue
                    Catch ex As Exception
        MessageBox.Show("ApplyTextObject" & Environment.NewLine & _
"There is no >>" & vstrTextObject & _
"<< object in this report!")
    End Try
End Sub
            }
        }
**********/

Open in new window


Thoughts?  I really just need help tweaking the above code - samples would really help me as I am a novice at VB Script.

Thanks!
0
Comment
Question by:robthomas09
  • 2
5 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 2000 total points
ID: 39225211
is this really vbscript? or is it C# and VB.Net?

check "Passing a value to a parameter of the report" from http://emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
0
 

Author Comment

by:robthomas09
ID: 39228814
Thanks for the replies - as you can tell by the improper zone posting, I am unfamiliar with the code.  It's all been wizard generated by Visual Studio 2012 ultimate.   A colleague built me the piece to include the string station_id, and now I need to pass it to the crystal report parameter.   I have visited the above link, but am so unfamiliar with the code that I wasnt able to attempt anything more than what I did above:

                        CrystalDecisions.CrystalReports.Engine.TextObject).vstrTextValue = station_id

Open in new window


Any help with the syntax would save my life.

Thanks
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 39228838
I can't really do more then telling you to read again the article and to play with the demo code until you get your stuff working!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question