How to develop Query based crystal reports

  • Thread starter Thread starter Jlo
  • Start date Start date
J

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.ReportSource = Application.StartupPath + "//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
 
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.ReportSource = Application.StartupPath + "//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
-----------------------------------------
 
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>

/// CrystalReportsParameters 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(object sender, EventArgs e)

{

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

{

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

return;

}


this.Cursor = Cursors.WaitCursor;

CrystalDecisions.Shared.TableLogOnInfo t; //logging on to database

t = new CrystalDecisions.Shared.TableLogOnInfo();

t.ConnectionInfo.DatabaseName = mLogger.RegGetStringValue("MyApp",
"Database", "Server");


t.ConnectionInfo.UserID = "myuser";

t.ConnectionInfo.Password = "mypassword";

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

string sReport = dgReports.SelectedRows[0].Cells[1].Value.ToString();


ReportDocument r;

CrystalReportParameters.ICrystalParameters c = new
CrystalReportParameters.clsMain() ; // Pretty parameter screen courtesy of
Bill Sergio, otherwise use parameterfields collection of ReportDocument

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

if(r!=null)

{

crv.LogOnInfo = new CrystalDecisions.Shared.TableLogOnInfos();//crv is the
Crystal Reports Viewer on the form

crv.LogOnInfo.Add(t);

crv.ReportSource = r;

}

else

{

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

}

this.Cursor=Cursors.Default;

return;

**********Internal report *********
Private Sub loadReportLeasedMeter(ByRef ds As dsMeterCost)

Try

Dim rd As New ReportMeterInvoice

rd.SetDataSource(ds)

Me.crvMain.ReportSource = rd

Catch ex As Exception

WriteErrorLog("frmReport.loadReportReprogram " & ex.Message)

End Try

End Sub

***************************************
 
Thanks Bob
bob said:
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>

/// CrystalReportsParameters 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(object sender, EventArgs e)

{

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

{

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

return;

}


this.Cursor = Cursors.WaitCursor;

CrystalDecisions.Shared.TableLogOnInfo t; //logging on to database

t = new CrystalDecisions.Shared.TableLogOnInfo();

t.ConnectionInfo.DatabaseName = mLogger.RegGetStringValue("MyApp",
"Database", "Server");


t.ConnectionInfo.UserID = "myuser";

t.ConnectionInfo.Password = "mypassword";

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

string sReport = dgReports.SelectedRows[0].Cells[1].Value.ToString();


ReportDocument r;

CrystalReportParameters.ICrystalParameters c = new
CrystalReportParameters.clsMain() ; // Pretty parameter screen courtesy of
Bill Sergio, otherwise use parameterfields collection of ReportDocument

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

if(r!=null)

{

crv.LogOnInfo = new CrystalDecisions.Shared.TableLogOnInfos();//crv is the
Crystal Reports Viewer on the form

crv.LogOnInfo.Add(t);

crv.ReportSource = r;

}

else

{

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

}

this.Cursor=Cursors.Default;

return;

**********Internal report *********
Private Sub loadReportLeasedMeter(ByRef ds As dsMeterCost)

Try

Dim rd As New ReportMeterInvoice

rd.SetDataSource(ds)

Me.crvMain.ReportSource = rd

Catch ex As Exception

WriteErrorLog("frmReport.loadReportReprogram " & ex.Message)

End Try

End Sub

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

Jlo said:
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.ReportSource = Application.StartupPath + "//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
 
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 said:
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>

/// CrystalReportsParameters 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(object sender, EventArgs e)

{

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

{

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

return;

}


this.Cursor = Cursors.WaitCursor;

CrystalDecisions.Shared.TableLogOnInfo t; //logging on to database

t = new CrystalDecisions.Shared.TableLogOnInfo();

t.ConnectionInfo.DatabaseName = mLogger.RegGetStringValue("MyApp",
"Database", "Server");


t.ConnectionInfo.UserID = "myuser";

t.ConnectionInfo.Password = "mypassword";

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

string sReport = dgReports.SelectedRows[0].Cells[1].Value.ToString();


ReportDocument r;

CrystalReportParameters.ICrystalParameters c = new
CrystalReportParameters.clsMain() ; // Pretty parameter screen courtesy of
Bill Sergio, otherwise use parameterfields collection of ReportDocument

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

if(r!=null)

{

crv.LogOnInfo = new CrystalDecisions.Shared.TableLogOnInfos();//crv is the
Crystal Reports Viewer on the form

crv.LogOnInfo.Add(t);

crv.ReportSource = r;

}

else

{

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

}

this.Cursor=Cursors.Default;

return;

**********Internal report *********
Private Sub loadReportLeasedMeter(ByRef ds As dsMeterCost)

Try

Dim rd As New ReportMeterInvoice

rd.SetDataSource(ds)

Me.crvMain.ReportSource = rd

Catch ex As Exception

WriteErrorLog("frmReport.loadReportReprogram " & ex.Message)

End Try

End Sub

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

Jlo said:
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.ReportSource = Application.StartupPath + "//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
 
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(object sender, EventArgs e)

{

TetsRpt t = new TetsRpt();

crv.ReportSource = 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 said:
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 said:
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>

/// CrystalReportsParameters 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(object sender, EventArgs e)

{

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

{

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

return;

}


this.Cursor = Cursors.WaitCursor;

CrystalDecisions.Shared.TableLogOnInfo t; //logging on to database

t = new CrystalDecisions.Shared.TableLogOnInfo();

t.ConnectionInfo.DatabaseName = mLogger.RegGetStringValue("MyApp",
"Database", "Server");


t.ConnectionInfo.UserID = "myuser";

t.ConnectionInfo.Password = "mypassword";

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

string sReport = dgReports.SelectedRows[0].Cells[1].Value.ToString();


ReportDocument r;

CrystalReportParameters.ICrystalParameters c = new
CrystalReportParameters.clsMain() ; // Pretty parameter screen courtesy
of
Bill Sergio, otherwise use parameterfields collection of ReportDocument

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

if(r!=null)

{

crv.LogOnInfo = new CrystalDecisions.Shared.TableLogOnInfos();//crv is
the
Crystal Reports Viewer on the form

crv.LogOnInfo.Add(t);

crv.ReportSource = r;

}

else

{

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

}

this.Cursor=Cursors.Default;

return;

**********Internal report *********
Private Sub loadReportLeasedMeter(ByRef ds As dsMeterCost)

Try

Dim rd As New ReportMeterInvoice

rd.SetDataSource(ds)

Me.crvMain.ReportSource = rd

Catch ex As Exception

WriteErrorLog("frmReport.loadReportReprogram " & ex.Message)

End Try

End Sub

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

Jlo said:
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.ReportSource = Application.StartupPath + "//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
 
Jlo said:
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.ReportSource = Application.StartupPath + "//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(fileName);
report.Database.Tables[string name or int index].SetDataSource(dataTable);

HTH
JB
 
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
 
Back
Top