Solved

Visual Studio, C, Pass Form Variable to Report Parameter

Posted on 2013-06-05
4
468 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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!
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

856 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