Solved

Visual Studio, C, Pass Form Variable to Report Parameter

Posted on 2013-06-05
4
450 Views
Last Modified: 2013-06-05
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
            }
        }
**********/


Thoughts?

Thanks
0
Comment
Question by:robthomas09
  • 2
  • 2
4 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 39222371
Why did you close your other question if you still needed help?
The reference I gave you has the code for a full running application
http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx

You have to call the procedure ApplyTextObject with your parameter name and the value you want to pass to it.

mlmcc
0
 

Author Comment

by:robthomas09
ID: 39222599
I'm god-awful at VB scripting, and need some help with the actual syntax.  I threw together my best guess after reading some tutorials with the code above.  I still have a ways to go.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39222609
I don't know VB Script so I can't help you there

mlmcc
0
 

Author Comment

by:robthomas09
ID: 39223114
im going to close and repost this one as it seems other coders tend to ignore tickets that have a few comments on them already.  I do appreciate your links though.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now