Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Parameter with record filter didn't create WHERE Post Reply Post New Topic
Author Message
gszabo
Newbie
Newbie


Joined: 22 Mar 2012
Online Status: Offline
Posts: 3
Quote gszabo Replybullet Topic: Parameter with record filter didn't create WHERE
     Posted: 22 Mar 2012 at 9:21pm
Hi!
 
I defined a parameter and a record filter with this parameter in a report based on an MSSQL connection. I wanted the Crystal R to create a WHERE clause into the SQL Select, but it didn't do it.
The rcord filter was very simple:
 
{<table>.<column>} = {?parameter}
 
If I replaced the {?parameter} to 1 constant the WHERE clause was created.
 
How can I force CR to create the WHERE clause with the parameter in order to read only the selected record from the database and not the all records?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Mar 2012 at 3:46am
Usually when linking directly to the tables, you would add your filter to the record selection filter criteria, but I don't know if that will generate a where clause or not (been a looong time since I wrote a report like that).
 
If you want the most control over your record selection, write a stored proc.  Then you just pass the parameters to the stored proc, and your database will use your parameter in the where clause....because you told it to.
 
Stored procs also open a whole new level of reporting as you can perform actions in the proc that CR (or any reporting system) simply can't do. In addition you can specify additional fields that can contain values that have meaning to report alone and not the database...can be a field that can be used for grouping and sorting, or it can be a flag that says to print the row, or force a page break, or a lookup table (as you can return more than 1 table to the report and link them in the report)...it is up to you, and also can make your life much easier.
 
sorry, I can get carried away.
 
HTH
IP IP Logged
gszabo
Newbie
Newbie


Joined: 22 Mar 2012
Online Status: Offline
Posts: 3
Quote gszabo Replybullet Posted: 23 Mar 2012 at 7:01am
Thank you the reply. I changed the method because I felt that I could not get control over the where clause. Some years ago I created Crystal reports and my method was to define the structure of data source with an xsd and give the data through a DataSet collected by me. Now I wanted to repeat this method but though every name was correct the report still was empty. Here is the code:

public class DeliveryFactory

{

private ToolPoolingDataContext DC;

private String reportPath = @"c:\Develop\Viewstore\ToolPooling\bugstools_GB_Utilities\ToolPooling\ToolPoolingService\Reports\";

public DeliveryFactory(ToolPoolingDataContext dc)

{

DC = dc;

}

public void CreateReport(int rental_ID)

{

List<V_DELIVERY> del = (from d in DC.V_DELIVERies where d.Rental_ID == rental_ID select d).ToList();

if (del.Count == 0)

return;

List<V_TOOL> tool = (from d in DC.V_TOOLs where d.Rental_ID == rental_ID select d).ToList();

if (tool.Count == 0)

return;

Delivery rep = new Delivery();

try

{

DataSet dsDelivery = new DataSet("DeliverySchema");

DataTable dtDel = new DataTable("V_DELIVERY");

dtDel.Columns.Add("AllocatedByName", typeof(String));

dtDel.Columns.Add("City", typeof(String));

dtDel.Columns.Add("CompanyName", typeof(String));

dtDel.Columns.Add("ContactName", typeof(String));

dtDel.Columns.Add("ContactOrgUnit", typeof(String));

dtDel.Columns.Add("ContactPhone", typeof(String));

dtDel.Columns.Add("CountryName", typeof(String));

dtDel.Columns.Add("Currency", typeof(String));

dtDel.Columns.Add("Location", typeof(String));

dtDel.Columns.Add("PostalCode", typeof(String));

dtDel.Columns.Add("Rental_ID", typeof(int));

dtDel.Columns.Add("ToolCount", typeof(int));

dtDel.Columns.Add("UsingStart", typeof(DateTime));

dsDelivery.Tables.Add(dtDel);

DataRow dtRow = dtDel.Rows.Add();

dtRow["AllocatedByName"] = del[0].AllocatedByName;

dtRow["City"] = del[0].City;

dtRow["CompanyName"] = del[0].CompanyName;

dtRow["ContactName"] = del[0].ContactName;

dtRow["ContactOrgUnit"] = del[0].ContactOrgUnit;

dtRow["ContactPhone"] = del[0].ContactPhone;

dtRow["CountryName"] = del[0].CountryName;

dtRow["Currency"] = del[0].Currency;

dtRow["Location"] = del[0].Location;

dtRow["PostalCode"] = del[0].PostalCode;

dtRow["Rental_ID"] = del[0].Rental_ID;

dtRow["ToolCount"] = del[0].ToolCount;

dtRow["UsingStart"] = del[0].UsingStart;

DataTable dtTool = new DataTable("V_TOOL");

dtTool.Columns.Add("AccessoryName", typeof(String));

dtTool.Columns.Add("no", typeof(int));

dtTool.Columns.Add("Rental_ID", typeof(int));

dtTool.Columns.Add("SN", typeof(String));

dtTool.Columns.Add("ToolName", typeof(String));

dtTool.Columns.Add("Tool_ID", typeof(int));

dsDelivery.Tables.Add(dtTool);

foreach (V_TOOL t in tool)

{

dtRow = dtTool.Rows.Add();

dtRow["AccessoryName"] = t.AccessoryName;

dtRow["no"] = t.no;

dtRow["Rental_ID"] = t.Rental_ID;

dtRow["SN"] = t.SN;

dtRow["ToolName"] = t.ToolName;

dtRow["Tool_ID"] = t.Tool_ID;

}

rep.SetDataSource(dsDelivery);

//rep.ReadRecords();

rep.ExportToDisk(ExportFormatType.PortableDocFormat, reportPath + "Delivery.pdf");

}

catch (Exception e)

{

}

}

}

The report was created with the proper DataTable names and proper Field names but no data was inserted into the report when I used the SetDataSource method. Both of two tables contained data. Could you tell me what is wrong?

IP IP Logged
gszabo
Newbie
Newbie


Joined: 22 Mar 2012
Online Status: Offline
Posts: 3
Quote gszabo Replybullet Posted: 23 Mar 2012 at 7:20am

I have found the bug: I forgot to remove a record selection forumla which was not needed after the reconfiguring of report and this formula filtered out the records in the DataSet.

I am sorry for the second question: it is solved. I would have been happy if I could controled the WHERE clause but it is not so important.

By
Gabor
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Mar 2012 at 7:28am
personally, I develop reports in much the same way.  I get the dataset and push it the report.  I tend to have .Net write the xml with data and schema so that it is easier to debug/layout. 
Other than that....well, that's why I am not sure about the where clause.
I don't need it as I control the where clause through the proc.


Edited by lockwelle - 23 Mar 2012 at 7:29am
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum