cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Report with text(csv) data file, can we set it as input parameter?

Former Member
0 Kudos

Hi,

I am a new user of Crystal Reports 2008.

I have created a report with charts in it. The input data comes from a csv text file.

Can I set the name of this text file as an input parameter?

as I need to generate 44 similar reports with different text filenames(and data)?

Thank you.

Regards

Accepted Solutions (1)

Accepted Solutions (1)

former_member292966
Active Contributor
0 Kudos

Hi,

A parameter can't be used to change the database information. How will you be running the report? In Crystal, Report Server, application?

In Crystal you'll have to go to Database | Set Datasource Location and select the CSV file.

If you are running the report from the Report Server, your report will need to use ODBC to connect to the CSV file but you will either need to have 1 datasource for each CSV and point to the correct datasource each time you run the report or copy the CSV file to a common folder and have it renamed the file with the original CSV filename so the report can find it.

If you are using an application, then you can point the report to any csv file you want as long as your application has a way for the user to select it and pass the new file name and location to the report.

Hope this helps,

Brian

Former Member
0 Kudos

Thanks Brian.

I will be running the report in an application but I do it this way.

I design the report first in crystal reports and save my .rpt file in a folder.

Therefore, my application only does the following:

1) create a reportDocument object,

2) load the report (name is passed as input);

3) refreshes it

4) and finally export it to a pdf file.

So in this case, since the only input to my application is the report filename, I am not able to figure out how

I can also pass the data file name as an input.

Can I set this up when I am designing the report in crystal reports itself?

Thank you.

Former Member
0 Kudos

is your application .net?

Former Member
0 Kudos

I have a C# application compiled as an executable that I run daily.

former_member292966
Active Contributor
0 Kudos

Hi,

Well you just made life for yourself easy with the .NET application. If your report is loading the CSV file directly, not using ODBC, then you can use LogonInfo to point the report to the new CSV file. This will do the same as going to Database | Set Datasource Location in Crystal.

In your application, you can pass the path to the CSV from a common dialog or text box to LogonInfo. To know what to pass, open the report in Crystal and go to Database | Set Datasource Location. Open the database properties and you will see the: Database Name is the path where your CSV is located. In the properties for the table you can see: Table Name which will be the CSV's filename.

Good luck,

Brian

Former Member
0 Kudos

Brian,

Thanks much, that helps a lot.

So what you are saying is that I call the setDataSource() function of the ReportDocument object before

calling it's Refresh function?

I do see there is a available function by that name.

Thanks!

Sachin

former_member292966
Active Contributor
0 Kudos

Hi Sachin,

Not the SetDataSource that's used if the report is connecting to DAO, ADO, RDO. Look for LogonInfo in ReportDocument.Database.Tables.

Do a search for LogonInfo in the .NET forum.

[;

Good luck,

Brian

Former Member
0 Kudos

Brian,

I added the text file as follow, new connection -> Access/Excell (DAO) -> select the file and the database type as text.

Does that qualify the data as a DAO object or is it still a plain text file.

If it qualifies as as DAO then I need to use the setDataSource otherwise the LoginInfo.

Thanks for your answers.

Sachin

former_member292966
Active Contributor
0 Kudos

Hi Sachin,

This still qualifies as a text file. So you will have to use LogonInfo.

Thanks,

Brian

Former Member
0 Kudos

Brian.

Thanks much for all the help.

I will try that out.

Former Member
0 Kudos

Hi Brian,

I am doing the following but it is not working, I still get the old report (generated with previous file) as an output.

I do

cryRpt = new ReportDocument();

cryRpt.Load(reportfile);

cryRpt.Database.Tables[0].LogOnInfo.TableName = "myOHLCFile_BS_NEW#csv";

cryRpt.Refresh();

and I also tried

Tables tables = cryRpt.Database.Tables;

TableLogOnInfo tableLogonInfo;

tableLogonInfo = tables[0].LogOnInfo;

Console.WriteLine(tableLogonInfo.TableName);

tableLogonInfo.TableName = "myOHLCFile_BS_NEW#csv";

cryRpt.Database.Tables[0].ApplyLogOnInfo(tableLogonInfo);

cryRpt.Refresh();

Both of them do not work.

When I check the new TableName in the tableLogonInfo object, it is there but the reportDocument.refresh() is not refreshing the data I believe.

Any suggestions?

Thanks

sachin

former_member292966
Active Contributor
0 Kudos

Hi Sachin,

Your second one loosk correct. The first time I tried I missed the ApplyLogonInfo completely.

The other thing I ran into was to turn off Save Date with Report in the report itself. Open the report in Crystal and go to File. Uncheck Save Data with Report. I found even though I called Refresh in my app as well, it didn't refresh at all.

Good luck,

Brian

Former Member
0 Kudos

Hi Brian,

I unchecked the save data with report and reran my code but it did not help.

I also later on unchecked "Verify on first refresh" but no change.

Any other options that I should try?

what should I expect once I do a refresh on the report, should it change the timestamp on the rpt file?

Because for me it is not doing that and my exported pdf file is never different.

Thanks,

sachin

Former Member
0 Kudos

Did you try VERIFY DATABASE ? I did not see it mentioned...

Former Member
0 Kudos

Debi,

Thanks.

Yes I did put verifyDatabase before and after the Refresh call and in both cases it did not work.

former_member292966
Active Contributor
0 Kudos

Hi,

One of two things is happening then. Either the LogonInfo is pointing to the same CSV as the report was designed with containing the same records and you won't see any difference or LogonInfo is being ignored and has located the original CSV and using that.

As a test, remove the CSV or point the LogonInfo to a different folder that has no CSV so your report cannot find it. Run your application. I would expect an error to happen. This is good because that means LogonInfo is trying to hit the CSV.

Now point LogonInfo back to the folder with the new CSV. Make sure this is a different CSV than the report was created with. Hopefully you will see records now.

If the first test produces the report with no errors then we know the report still has Saved Data. Make sure you have opened the correct Report in Crystal, removed the Saved Data and resave the report. Make sure this is the report being opened in your application.

Step through you application and check the LogonInfo collection. Make sure the database is pointing to the correct folder and the TableName is pointing to the correct CSV file.

Good luck,

Brian

Former Member
0 Kudos

Brian,

Thanks much.

I did exactly what you said.

Just to see any change, I first gave a bad report file name just to see if I am accidentally pointing to a different file,

but I got an error saying report not found.

Then I renamed my original datafile name and generated a report and it still generated one without giving an error.

Then I also gave a junk name to the logoninfo and printed that name, the new name was assigned to logoninfo, but the code did not error out.

It ended up generating the report.

Now here is what I think is happening,

1) The save data in report option seems to be still on even though I have turned it off in 2 locations

a) file -> Report Options

b) file -> Options -> Reporting tab.

2) For some reason the logoninfo is getting ignored as well.

Since I did not see any answers yesterday I posted a link to this thread on the .Net forum

and Ludek Uher says that I am connecting to the text file via a DAO database engine and so need to use the same code for changing the text file as for changing an Access database.

But the link he gave me tells me to try the same thing that we have been trying..

Here is my plan,

1) I will first try and find out why my save data with report option is still on ( but it shows off in Crystal ).

2) why is LogonInfo getting ignored.

Meanwhile any suggestions from anyone are welcome.

Former Member
0 Kudos

I just checked in the code by printing the following:

Console.WriteLine(cryRpt.ReportOptions.EnableSaveDataWithReport);

and it comes out to be false, thus "save data with Report" is turned off for sure.

This means I am using the wrong way of changing my tablename? LogonInfo is not the right way to go?

Former Member
0 Kudos

Hi Brian,

One big thing that I did not mention and did not even strike my mind until now was that I have all charts in my report.

And when I say it does not work, I mean that my charts are not getting updated.

Is there a separate setting for the charts where the data gets saved by default or something?

I read that Crystal report uses external charting tool, so do I have controls to it to update the data?

Thanks.

Former Member
0 Kudos

Hi Brian,

Finally I figured it out.

As I mentioned in my earlier post, I only had charts in my report and that was the reason that it was not getting updated.

I read on another post that crystal reports uses third party charting tool, that for some reason triggered me into thinking that may be the plain data fields would get updated but not the charts.

So I added a couple of data fields from the data set and it did the trick. My data got refreshed and displayed from the new file.

Now all I had to do was to suppress those data fields and my charts display fine with the new data file.

I still have couple of issues with the new displayed charts.

1) One of my line chart has values printed as the zero for the data that is missing ( I have selected to break for missing data)

2) a couple of legends are displayed bad.

But I guess these issues ask for another search on the posts or posting a new thread.

If you have some suggestions on this, please do let me know.

Thank you very much for all your help.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi there I am trying to do a similar thing but am having difficulty.  I have a report that uses 4 sets of csv files located in a directory.  The report runs fine in the crystal application.  When I package this report and run it in my VB6 application it will open the report fine.  When I move the CSV files to another location (ie different directory) and try to set the location it doesn't work.  What am I doing wrong.

Does anyone have any sample code for repointing crystal to another directory for CSV files?

thanks

Ian

Former Member
0 Kudos

I tried the given solution thinking that it will work, but it did not.