Solved

Visual Studio, C, Pass Form Variable to Report Parameter

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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 and use conditional statements in the C programming language.

832 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