Crystal Reports in VB.NET

  • Thread starter Stephen Plotnick
  • Start date
S

Stephen Plotnick

I am able to create a Crystal report and get it to go to the screen., print,
Excel, etc.

What I want to do now is allow for my VB.NET (2003) program to dynamically
build a "WHERE clause"

For example;

I have 4000 records in an Access DB and I'm displaying Name, Address, State,
ZIP. At this time all 4000 records are being displayed. I want to the user
to print all customers in "IL". How can I build this request in the VB.NET
program and than call the form where the Crystal report is located and
display only records for "IL".

Thanks in advance,
Steve
 
A

Alex

Hi Stephan

There are 2 ways of doing this, You can create a datatable or dataset
with your where clause and pass it to your report like this:

//dbmodtimeSheet, is a database class you would use ExecuteScaler etc
like you would normally do to get the datatable.

dim dt as new datatable
dim report as As New TimeSheetReporta
dt = dbmodtimeSheet.GetDataTable("SELECT * FROM History WHERE Name =
'ARITCHIE'")
report.SetDataSource(dt)
reportviewer.RunReport(report)

Or you could, use the report filter to do it, which is the way I
prefer.

//NewTimeSheetReporta is the name of your report.
dim report as As New TimeSheetReporta
//LogonInfo is set up to prevent it asking you for the login all the
time.
LogonInfo.ConnectionInfo.UserID = user
LogonInfo.ConnectionInfo.Password = pw
report.Database.Tables(0).ApplyLogOnInfo(LogonInfo)
report.Database.Tables(1).ApplyLogOnInfo(LogonInfo)
report.RecordSelectionFormula = "{History.Weekno} = " & NumWeekno.Text
reportviewer.RunReport(report)
 
S

Stephen Plotnick

Thanks,

It seems the reportviewer is for VB 2005. Is there an equivalent for vb.net
(2003)?

Steve
 
S

Stephen Plotnick

reportviewer.RunReport(report)

Gives me an error. Am I mssing something that needs to added somewhere?
 
A

Alex

Well you need to put a report viewer on a form somewere and the
"TimeSheetReporta" report object needs to be a report you have created
in your project other then that I cnat think what else you need
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top