473,748 Members | 11,145 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 6717
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
2429
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
9641
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
1452
by: 2003et | last post by:
how can I change the query for the crystal reports, runtime? Thanks in advance
4
4644
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
4427
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
1295
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
8828
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
9367
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...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
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
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.