Solved

Pass Form Variable to Report Parameter

Posted on 2013-06-05
5
370 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 500 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

679 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