473,734 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to develop Query based crystal reports

Jlo
Hi, I have a c# winforms application.

When I call the report file, it shows me all the records in the table.

How can I make it to call only a particular range.

i have the following code
Viewer1.ReportS ource = Application.Sta rtupPath + "//Label.rpt";

How can I assign it a dataset which have the data of a particular range.

Gurus, I hope I am clear.

Need it urgently, as my client is waiting for this for a long time.

thanks

-jlo


Mar 20 '07 #1
7 6715
Hi, I have a c# winforms application.
>
When I call the report file, it shows me all the records in the table.

How can I make it to call only a particular range.

i have the following code
Viewer1.ReportS ource = Application.Sta rtupPath + "//Label.rpt";

How can I assign it a dataset which have the data of a particular range.

Gurus, I hope I am clear.

Need it urgently, as my client is waiting for this for a long time.

IMHO, the query must be provided in the RPT (report) and not in the viewer.
Viewer will display all content as taken up from the report.

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
Mar 20 '07 #2
bob
Hi jlo,
Some options:
EXTERNAL REPORTS (as per your example
1) Parameterised report with Stored procedure
Ideally you would have a stored procedure in the database that takes the
'range' parameters.
The report would then be altered to have the sproc as its datasource and it
would provide the parameters
2) Parameterised report straight from table
You can alter the report to have the range parameters and have it limit the
table data displayed (Not as efficient.)

INTERNAL REPORT
(Disadvantage of internal report is new installation needed if report
changes.)
Assumes a datalayer in your application.
Make a typed dataset and fill it.
Design a internal report that takes the typed dataset as its datasource.
Hang that in the Report viewer

The visual studio crystal engine has all the necessary classes to allow you
to manipulate the report before you hang it in the viewer.
Some c# code dealing with a parameterised external report and some vb
dealing with an internal report follows
hth
bob
/// <summary>

/// CrystalReportsP arameters is a dll based on Bill Sergio's article

/// http://www.codeproject.com/useritems/crystalWin.asp

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>
private void cmdView_Click(o bject sender, EventArgs e)

{

if (dgReports.Sele ctedRows.Count == 0) //Reports are listed in a grid

{

MessageBox.Show (rm.GetString(" String133")); //pick a report

return;

}
this.Cursor = Cursors.WaitCur sor;

CrystalDecision s.Shared.TableL ogOnInfo t; //logging on to database

t = new CrystalDecision s.Shared.TableL ogOnInfo();

t.ConnectionInf o.DatabaseName = mLogger.RegGetS tringValue("MyA pp",
"Database", "Server");
t.ConnectionInf o.UserID = "myuser";

t.ConnectionInf o.Password = "mypassword ";

string sReportFile = mstrReportPath +
dgReports.Selec tedRows[0].Cells[1].Value.ToString ();

string sReport = dgReports.Selec tedRows[0].Cells[1].Value.ToString ();
ReportDocument r;

CrystalReportPa rameters.ICryst alParameters c = new
CrystalReportPa rameters.clsMai n() ; // Pretty parameter screen courtesy of
Bill Sergio, otherwise use parameterfields collection of ReportDocument

r = c.DisplayParame ters(sReport, sReportFile);//Displays parameters , takes
values returns ReportDoc

if(r!=null)

{

crv.LogOnInfo = new CrystalDecision s.Shared.TableL ogOnInfos();//crv is the
Crystal Reports Viewer on the form

crv.LogOnInfo.A dd(t);

crv.ReportSourc e = r;

}

else

{

MessageBox.Show (rm.GetString(" String77"));

}

this.Cursor=Cur sors.Default;

return;

**********Inter nal report *********
Private Sub loadReportLease dMeter(ByRef ds As dsMeterCost)

Try

Dim rd As New ReportMeterInvo ice

rd.SetDataSourc e(ds)

Me.crvMain.Repo rtSource = rd

Catch ex As Exception

WriteErrorLog(" frmReport.loadR eportReprogram " & ex.Message)

End Try

End Sub

*************** *************** *********

"Jlo" <lo*******@gmai l.comwrote in message
news:uk******** ******@TK2MSFTN GP05.phx.gbl...
Hi, I have a c# winforms application.

When I call the report file, it shows me all the records in the table.

How can I make it to call only a particular range.

i have the following code
Viewer1.ReportS ource = Application.Sta rtupPath + "//Label.rpt";

How can I assign it a dataset which have the data of a particular range.

Gurus, I hope I am clear.

Need it urgently, as my client is waiting for this for a long time.

thanks

-jlo


Mar 20 '07 #3
Jlo
Thanks Bob
"bob" <bo*@nowhere.co mwrote in message
news:ek******** *****@TK2MSFTNG P03.phx.gbl...
Hi jlo,
Some options:
EXTERNAL REPORTS (as per your example
1) Parameterised report with Stored procedure
Ideally you would have a stored procedure in the database that takes the
'range' parameters.
The report would then be altered to have the sproc as its datasource and
it
would provide the parameters
2) Parameterised report straight from table
You can alter the report to have the range parameters and have it limit
the
table data displayed (Not as efficient.)

INTERNAL REPORT
(Disadvantage of internal report is new installation needed if report
changes.)
Assumes a datalayer in your application.
Make a typed dataset and fill it.
Design a internal report that takes the typed dataset as its datasource.
Hang that in the Report viewer

The visual studio crystal engine has all the necessary classes to allow
you
to manipulate the report before you hang it in the viewer.
Some c# code dealing with a parameterised external report and some vb
dealing with an internal report follows
hth
bob
/// <summary>

/// CrystalReportsP arameters is a dll based on Bill Sergio's article

/// http://www.codeproject.com/useritems/crystalWin.asp

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>
private void cmdView_Click(o bject sender, EventArgs e)

{

if (dgReports.Sele ctedRows.Count == 0) //Reports are listed in a grid

{

MessageBox.Show (rm.GetString(" String133")); //pick a report

return;

}
this.Cursor = Cursors.WaitCur sor;

CrystalDecision s.Shared.TableL ogOnInfo t; //logging on to database

t = new CrystalDecision s.Shared.TableL ogOnInfo();

t.ConnectionInf o.DatabaseName = mLogger.RegGetS tringValue("MyA pp",
"Database", "Server");
t.ConnectionInf o.UserID = "myuser";

t.ConnectionInf o.Password = "mypassword ";

string sReportFile = mstrReportPath +
dgReports.Selec tedRows[0].Cells[1].Value.ToString ();

string sReport = dgReports.Selec tedRows[0].Cells[1].Value.ToString ();
ReportDocument r;

CrystalReportPa rameters.ICryst alParameters c = new
CrystalReportPa rameters.clsMai n() ; // Pretty parameter screen courtesy of
Bill Sergio, otherwise use parameterfields collection of ReportDocument

r = c.DisplayParame ters(sReport, sReportFile);//Displays parameters ,
takes
values returns ReportDoc

if(r!=null)

{

crv.LogOnInfo = new CrystalDecision s.Shared.TableL ogOnInfos();//crv is the
Crystal Reports Viewer on the form

crv.LogOnInfo.A dd(t);

crv.ReportSourc e = r;

}

else

{

MessageBox.Show (rm.GetString(" String77"));

}

this.Cursor=Cur sors.Default;

return;

**********Inter nal report *********
Private Sub loadReportLease dMeter(ByRef ds As dsMeterCost)

Try

Dim rd As New ReportMeterInvo ice

rd.SetDataSourc e(ds)

Me.crvMain.Repo rtSource = rd

Catch ex As Exception

WriteErrorLog(" frmReport.loadR eportReprogram " & ex.Message)

End Try

End Sub

*************** *************** *********

"Jlo" <lo*******@gmai l.comwrote in message
news:uk******** ******@TK2MSFTN GP05.phx.gbl...
>Hi, I have a c# winforms application.

When I call the report file, it shows me all the records in the table.

How can I make it to call only a particular range.

i have the following code
Viewer1.Report Source = Application.Sta rtupPath + "//Label.rpt";

How can I assign it a dataset which have the data of a particular range.

Gurus, I hope I am clear.

Need it urgently, as my client is waiting for this for a long time.

thanks

-jlo



Mar 20 '07 #4
Jlo
Hey, the Internal report is exactly what I wanna do.

Is there a sample code anywhere to see how it is done. THe link you provided
is only for External reports.

I tried working on internal reports, but I get
error"'Tracker. bin.Debug.Label ' denotes a 'class' which is not valid in the
given context
"
The file name is Label.rpt which is in the debug folder. There is an
automatically generated Label.cs file, to which I try to setdatasource() ,
but the above error occurs.

Pls bob, help me out on this. Thanks.

"bob" <bo*@nowhere.co mwrote in message
news:ek******** *****@TK2MSFTNG P03.phx.gbl...
Hi jlo,
Some options:
EXTERNAL REPORTS (as per your example
1) Parameterised report with Stored procedure
Ideally you would have a stored procedure in the database that takes the
'range' parameters.
The report would then be altered to have the sproc as its datasource and
it
would provide the parameters
2) Parameterised report straight from table
You can alter the report to have the range parameters and have it limit
the
table data displayed (Not as efficient.)

INTERNAL REPORT
(Disadvantage of internal report is new installation needed if report
changes.)
Assumes a datalayer in your application.
Make a typed dataset and fill it.
Design a internal report that takes the typed dataset as its datasource.
Hang that in the Report viewer

The visual studio crystal engine has all the necessary classes to allow
you
to manipulate the report before you hang it in the viewer.
Some c# code dealing with a parameterised external report and some vb
dealing with an internal report follows
hth
bob
/// <summary>

/// CrystalReportsP arameters is a dll based on Bill Sergio's article

/// http://www.codeproject.com/useritems/crystalWin.asp

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>
private void cmdView_Click(o bject sender, EventArgs e)

{

if (dgReports.Sele ctedRows.Count == 0) //Reports are listed in a grid

{

MessageBox.Show (rm.GetString(" String133")); //pick a report

return;

}
this.Cursor = Cursors.WaitCur sor;

CrystalDecision s.Shared.TableL ogOnInfo t; //logging on to database

t = new CrystalDecision s.Shared.TableL ogOnInfo();

t.ConnectionInf o.DatabaseName = mLogger.RegGetS tringValue("MyA pp",
"Database", "Server");
t.ConnectionInf o.UserID = "myuser";

t.ConnectionInf o.Password = "mypassword ";

string sReportFile = mstrReportPath +
dgReports.Selec tedRows[0].Cells[1].Value.ToString ();

string sReport = dgReports.Selec tedRows[0].Cells[1].Value.ToString ();
ReportDocument r;

CrystalReportPa rameters.ICryst alParameters c = new
CrystalReportPa rameters.clsMai n() ; // Pretty parameter screen courtesy of
Bill Sergio, otherwise use parameterfields collection of ReportDocument

r = c.DisplayParame ters(sReport, sReportFile);//Displays parameters ,
takes
values returns ReportDoc

if(r!=null)

{

crv.LogOnInfo = new CrystalDecision s.Shared.TableL ogOnInfos();//crv is the
Crystal Reports Viewer on the form

crv.LogOnInfo.A dd(t);

crv.ReportSourc e = r;

}

else

{

MessageBox.Show (rm.GetString(" String77"));

}

this.Cursor=Cur sors.Default;

return;

**********Inter nal report *********
Private Sub loadReportLease dMeter(ByRef ds As dsMeterCost)

Try

Dim rd As New ReportMeterInvo ice

rd.SetDataSourc e(ds)

Me.crvMain.Repo rtSource = rd

Catch ex As Exception

WriteErrorLog(" frmReport.loadR eportReprogram " & ex.Message)

End Try

End Sub

*************** *************** *********

"Jlo" <lo*******@gmai l.comwrote in message
news:uk******** ******@TK2MSFTN GP05.phx.gbl...
>Hi, I have a c# winforms application.

When I call the report file, it shows me all the records in the table.

How can I make it to call only a particular range.

i have the following code
Viewer1.Report Source = Application.Sta rtupPath + "//Label.rpt";

How can I assign it a dataset which have the data of a particular range.

Gurus, I hope I am clear.

Need it urgently, as my client is waiting for this for a long time.

thanks

-jlo



Mar 20 '07 #5
Bob
Hi Jlo,
1) Make a typed dataset that 'embodies' the data you want in the report.
2) Using your data layer, test fill the dataset.

Spend some time getting the dataset right. It saves time later because the
internal report seems to be sticky once it gets its hands on a dataset. i.e
Getting the report to accept an additional field from an altered dataset
requires mucking around with refreshing its datasource.

Happy that the dataset works then add a new crystal report to your project.

The add wizard will ask you for the data for the report. Point it at your
typed dataset which should now be visible under
'Project/Ado.Net Datasets'
Once the wizard has finished you can call an instance of the report like
any other class
Some test code.
I added a new report to my project called TetsRpt (dyslexia duh)
I used the data wizard to point it at an existing typed dataset under
Project/adoData.net
Now on the form that has the crystal viewer I can code
private void button1_Click(o bject sender, EventArgs e)

{

TetsRpt t = new TetsRpt();

crv.ReportSourc e = t;

}

The form now displays the empty report because I didn't bother to fill the
dataset.
What you appear to be trying to do at present is incorporate the current
external report, as far as I am aware you can't do that. Make a new blank
report and incoporate the layout of the external report into it.

Again the caveat that you getting into a canned scenario where any report
alteration will require a new application installation on the clients site
to propagate the change.

regards
bob

"Jlo" <lo*******@gmai l.comwrote in message
news:e4******** ******@TK2MSFTN GP02.phx.gbl...
Hey, the Internal report is exactly what I wanna do.

Is there a sample code anywhere to see how it is done. THe link you
provided is only for External reports.

I tried working on internal reports, but I get
error"'Tracker. bin.Debug.Label ' denotes a 'class' which is not valid in
the given context
"
The file name is Label.rpt which is in the debug folder. There is an
automatically generated Label.cs file, to which I try to setdatasource() ,
but the above error occurs.

Pls bob, help me out on this. Thanks.

"bob" <bo*@nowhere.co mwrote in message
news:ek******** *****@TK2MSFTNG P03.phx.gbl...
>Hi jlo,
Some options:
EXTERNAL REPORTS (as per your example
1) Parameterised report with Stored procedure
Ideally you would have a stored procedure in the database that takes the
'range' parameters.
The report would then be altered to have the sproc as its datasource and
it
would provide the parameters
2) Parameterised report straight from table
You can alter the report to have the range parameters and have it limit
the
table data displayed (Not as efficient.)

INTERNAL REPORT
(Disadvantag e of internal report is new installation needed if report
changes.)
Assumes a datalayer in your application.
Make a typed dataset and fill it.
Design a internal report that takes the typed dataset as its datasource.
Hang that in the Report viewer

The visual studio crystal engine has all the necessary classes to allow
you
to manipulate the report before you hang it in the viewer.
Some c# code dealing with a parameterised external report and some vb
dealing with an internal report follows
hth
bob
/// <summary>

/// CrystalReportsP arameters is a dll based on Bill Sergio's article

/// http://www.codeproject.com/useritems/crystalWin.asp

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>
private void cmdView_Click(o bject sender, EventArgs e)

{

if (dgReports.Sele ctedRows.Count == 0) //Reports are listed in a grid

{

MessageBox.Sho w(rm.GetString( "String133" )); //pick a report

return;

}
this.Cursor = Cursors.WaitCur sor;

CrystalDecisio ns.Shared.Table LogOnInfo t; //logging on to database

t = new CrystalDecision s.Shared.TableL ogOnInfo();

t.ConnectionIn fo.DatabaseName = mLogger.RegGetS tringValue("MyA pp",
"Database", "Server");
t.ConnectionIn fo.UserID = "myuser";

t.ConnectionIn fo.Password = "mypassword ";

string sReportFile = mstrReportPath +
dgReports.Sele ctedRows[0].Cells[1].Value.ToString ();

string sReport = dgReports.Selec tedRows[0].Cells[1].Value.ToString ();
ReportDocume nt r;

CrystalReportP arameters.ICrys talParameters c = new
CrystalReportP arameters.clsMa in() ; // Pretty parameter screen courtesy
of
Bill Sergio, otherwise use parameterfields collection of ReportDocument

r = c.DisplayParame ters(sReport, sReportFile);//Displays parameters ,
takes
values returns ReportDoc

if(r!=null)

{

crv.LogOnInf o = new CrystalDecision s.Shared.TableL ogOnInfos();//crv is
the
Crystal Reports Viewer on the form

crv.LogOnInfo. Add(t);

crv.ReportSour ce = r;

}

else

{

MessageBox.Sho w(rm.GetString( "String77") );

}

this.Cursor=Cu rsors.Default;

return;

**********Inte rnal report *********
Private Sub loadReportLease dMeter(ByRef ds As dsMeterCost)

Try

Dim rd As New ReportMeterInvo ice

rd.SetDataSour ce(ds)

Me.crvMain.Rep ortSource = rd

Catch ex As Exception

WriteErrorLog( "frmReport.load ReportReprogram " & ex.Message)

End Try

End Sub

************** *************** **********

"Jlo" <lo*******@gmai l.comwrote in message
news:uk******* *******@TK2MSFT NGP05.phx.gbl.. .
>>Hi, I have a c# winforms application.

When I call the report file, it shows me all the records in the table.

How can I make it to call only a particular range.

i have the following code
Viewer1.Repor tSource = Application.Sta rtupPath + "//Label.rpt";

How can I assign it a dataset which have the data of a particular range.

Gurus, I hope I am clear.

Need it urgently, as my client is waiting for this for a long time.

thanks

-jlo




Mar 20 '07 #6
Jlo wrote:
Hi, I have a c# winforms application.

When I call the report file, it shows me all the records in the table.

How can I make it to call only a particular range.

i have the following code
Viewer1.ReportS ource = Application.Sta rtupPath + "//Label.rpt";

How can I assign it a dataset which have the data of a particular range.

Gurus, I hope I am clear.

Need it urgently, as my client is waiting for this for a long time.

thanks

-jlo
ReportDocument report = new ReportDocument( );
report.Load(fil eName);
report.Database .Tables[string name or int index].SetDataSource( dataTable);

HTH
JB
Mar 21 '07 #7
Jlo
Hey Bob, its works, you have given fantastic lead and your hitch was right, I was trying ont he same old report.

Maaan....i am grateful to you.
Thanks dude.

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Mar 25 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2428
by: Chris | last post by:
Well I'm just a student wanting an economical approach in incorporating crystal reports with ASP so can anyone tell me how to handcode to use crystal reports with ASP together?
4
9639
by: Wayne Baswell | last post by:
I want to pass a date variable to a sql statement from Crystal Reports. The part of the query accepting the variables looks like: "Calendar_Date between To_Date('1-JUN-03','mm/dd/yy') and To_Date('30-JUN-03','mm/dd/yy')" And I'd be wanting to replace the date part of the query with a user-entered date. As I'm new to Oracle and Crystal, I don't know where to start. Is there a way to replace the '1-JUN-03' part with a variable in...
3
6915
by: Gheaci Maschl | last post by:
Hi all! I would like to have your opinion about my problem and my proposal how to solve it: Ingredients: - BTriev database - Crystal Reports - maybe MS Access - Liinos6 (small ERP software)
1
1451
by: 2003et | last post by:
how can I change the query for the crystal reports, runtime? Thanks in advance
4
4643
by: Andrew | last post by:
Hey all, Been working with the Crystal Report Viewer, and have run into a situation I am hoping someone can help me get past. This may be more of a CR question, but hoping for some CR gurus to stop by in here. Crystal's knowledgebase has made available a bunch of examples for both ASP.Net and VB.Net applications for download and review (I added the links at the end of this post). One of the examples is how to pass in a parameter to...
7
4426
by: John | last post by:
I am using Crystal Reports in my application I made using Visual Studio.NET. I installed my application on the client machine, with all the DLLs required(added the merge modules), the engine and the rest. When I start my application and, from it, try to open up a report I get an exception "Query engine error: C:\WINDOWS\Temp\temp_*******.rpt" with some wierd numbers instead of *******. Can anyone tell me what the problem is here and how to...
5
2403
by: Jay | last post by:
I am getting mixed messages from the asp.net website hosting providers - some say they do not support Crystal Reports due to a $25,000 per cpu licensing fee, others say all I need to do is install Crystal Reports XI (about $500) on a dedicated server and it will run fine. Will Reports developed with the embeded Crystal Reports in VS 2005 run in a Crystal Reports XI environment? -- Thanks
2
1294
by: balram | last post by:
i just want to know about how to retrive fields dynamically through vb in crystal reports.
1
3555
by: tanya2001 | last post by:
hi all now i have a query on crystal reports in .net.I have to generate a report in my webform by displaying one column vertically and other one horizontally....so how do u suggest...i should use it....i knw tht v do using d formula in crystal reports in .net but i have no idea of the formulae used in it....can somebody plzz help me generate this reports...thanx in advance..
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.