[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2237
  • Last Modified:

Assign values to the Text Field Crystal Report

    In our project, we are using crystal reports. Now I want to add the values which is getting from the .cs page to the Text Field presented in the crystal report page. How can I do this?
we are currently using front end Microsoft Visual studio 2005 and back end Microsoft SQL server 2005.
0
veradist
Asked:
veradist
  • 7
  • 7
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
veradistAuthor Commented:
Your given solution is in vb.net. But I want to know in C#.net. So, please give me the solution with the code of ASP.net with C#.net 2005.

Thanks in Advance...
0
 
Éric MoreauSenior .Net ConsultantCommented:
Add semi-colons to the end of each line and you are almost done! You basically need one line:

(CrystalDecisions.CrystalReports.Engine.TextObject)mrptDoc.ReportDefinition.ReportObjects(vstrTextObject).Text = _
vstrTextValue;

And it doesn't matter Windows or Web.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
veradistAuthor Commented:
(CrystalDecisions.CrystalReports.Engine.TextObject)mrptDoc.ReportDefinition.ReportObjects(vstrTextObject).Text = _vstrTextValue;

From the above code  .Text does not pop up in my asp.net with c# and then _vstrTextValue also doesn't appear.
pls give me the feasible solution

Thanks in Advance..
 private void ApplyTextObject(string vstrTextObject, string vstrTextValue)
    {
        try
        {
            
            (CrystalDecisions.CrystalReports.Engine.TextObject)doc.ReportDefinition.ReportObjects(vstrTextObject) = vstrTextValue;
 
 
           
        }
        catch (Exception e)
        {
            System.Windows.Forms.MessageBox.Show("Catch here", "Message:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, System.Windows.Forms.MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
        }
    }
 
   

Open in new window

0
 
Éric MoreauSenior .Net ConsultantCommented:
I made a mistake. there shouldn't be any underscore there.

as for the text property, it is probably not the correct casting.
0
 
Éric MoreauSenior .Net ConsultantCommented:
from http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=33132


CrystalDecisions.CrystalReports.Engine.TextObject HeaderCohort = ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportHeaderSection1.ReportObjects["HeaderCohort"]); 
 
HeaderCohort.Text = "This is what I want it to Say Now"; 

Open in new window

0
 
veradistAuthor Commented:
Ok now there is no error it runs well but it goes to the exception part. I haven't reach the solution
0
 
Éric MoreauSenior .Net ConsultantCommented:
and what is the exception? are you sure the field exists and it is spelled correctly?
0
 
veradistAuthor Commented:
The Exception is System.IndexOutOfRangeException: Index was outside the bounds of the array. at CrystalDecesions.CrystalReports.Engine.ReportObjects.get_Item(String Name) at Report.ApplyTextObject(String vstrTextObject, String vstrTextValue)in c:\Inetpub\wwwroot\Dashboard\Report.aspx.cs:line 52

This is the exception, now what can I do help me its very urgent
0
 
veradistAuthor Commented:
And my function is the following code snippet.
Then the calling function is

ApplyTextObject("txtInt_1", "Santhana Krishnan");
where txtInt_1 is the name of the TextObject and the "Santhana Krishnan" is the label which is appear to that particular TextObject.
private void ApplyTextObject(string vstrTextObject, string vstrTextValue)
    {
        try
        {
            CrystalDecisions.CrystalReports.Engine.TextObject HeaderCohort = ((CrystalDecisions.CrystalReports.Engine.TextObject)doc.ReportDefinition.ReportObjects["HeaderCohort"]);
            HeaderCohort.Text = "Veradis Technologies";
        }
        catch (Exception e)
        {
            System.Windows.Forms.MessageBox.Show("Catch here   -  "+e, "Message:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, System.Windows.Forms.MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
        }
    }

Open in new window

0
 
Éric MoreauSenior .Net ConsultantCommented:
the code posted is not using your variables!

this one is:
private void ApplyTextObject(string vstrTextObject, string vstrTextValue)
    {
        try
        {
            CrystalDecisions.CrystalReports.Engine.TextObject HeaderCohort = ((CrystalDecisions.CrystalReports.Engine.TextObject)doc.ReportDefinition.ReportObjects[vstrTextObject]);
            HeaderCohort.Text = vstrTextValue;
        }
        catch (Exception e)
        {
            System.Windows.Forms.MessageBox.Show("Catch here   -  "+e, "Message:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, System.Windows.Forms.MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
        }
    }

Open in new window

0
 
veradistAuthor Commented:
Ya now its working
Thanks & very kind of u....
Thanks a lot sir.

0
 
Éric MoreauSenior .Net ConsultantCommented:
If it is working, you should accept a comment to close it
0
 
veradistAuthor Commented:
Its a very timely help.
Thanks a lot to Expert Exchange...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now