crystal reporting in vb.net
-
I have created my crystal report and binded it to a crystalreportviewer. Once called everything works great. The report shows everything in the database. I am surprised I have gotten this far considering this is my first time using crystal reports with vb.net. I am trying to only pass one row in and display the one row only. How is this accomplished?:doh: I want to pass values of the one row and one row only to the report and display it. Thanks in advance:) Beginner in VB.Net
-
I have created my crystal report and binded it to a crystalreportviewer. Once called everything works great. The report shows everything in the database. I am surprised I have gotten this far considering this is my first time using crystal reports with vb.net. I am trying to only pass one row in and display the one row only. How is this accomplished?:doh: I want to pass values of the one row and one row only to the report and display it. Thanks in advance:) Beginner in VB.Net
there are a few ways you could do this. you could select the data that you wish to display out of your current data source and copy it to a different dataset with the same structure. then set the datasource of the report = the dataset with just the single row. or... you could just do everything the way you are currently doing it and create a parameter for the report. in your code you set this parameter = the unique id for the row which yuo wish to display. next, create a Record Selection Formula and have it select only the rows which match the parameter value. i used this method when i designed our company's new packing slip that we are now using in production. each way has it's +'s and -'s, try them and see which way works out best for yuor particular application. hope this helps.
-jim
-
there are a few ways you could do this. you could select the data that you wish to display out of your current data source and copy it to a different dataset with the same structure. then set the datasource of the report = the dataset with just the single row. or... you could just do everything the way you are currently doing it and create a parameter for the report. in your code you set this parameter = the unique id for the row which yuo wish to display. next, create a Record Selection Formula and have it select only the rows which match the parameter value. i used this method when i designed our company's new packing slip that we are now using in production. each way has it's +'s and -'s, try them and see which way works out best for yuor particular application. hope this helps.
-jim
Jim Matthews wrote: you could just do everything the way you are currently doing it and create a parameter for the report. in your code you set this parameter = the unique id for the row which yuo wish to display. next, create a Record Selection Formula and have it select only the rows which match the parameter value. i used this method when i designed our company's new packing slip that we are now using in production. I would like to do it the way explained above. Do you have any examples of this? In my database, the primary key is an autonumber named contactID. Is it possible to pass that value to the report and use it in the record selection formula? That sounds simple to do but don't know how to start it.:doh: Thanks again:) Beginner in ASP.Net and VB.Net
-
Jim Matthews wrote: you could just do everything the way you are currently doing it and create a parameter for the report. in your code you set this parameter = the unique id for the row which yuo wish to display. next, create a Record Selection Formula and have it select only the rows which match the parameter value. i used this method when i designed our company's new packing slip that we are now using in production. I would like to do it the way explained above. Do you have any examples of this? In my database, the primary key is an autonumber named contactID. Is it possible to pass that value to the report and use it in the record selection formula? That sounds simple to do but don't know how to start it.:doh: Thanks again:) Beginner in ASP.Net and VB.Net
no problem. :) i actually should have provided some source code here as the crystal objects are not very intuitive. (imho) 1. in your report create a parameter field called "ContactId" 2. in your report right click an empty area in the field explorer. go to "Report", then "Selection Formula" and then finally "Records". This should open the formula workshop. enter a formula for selection criteria like the following:
{Contact.ContactId} = {?ContactId}
where Contact is your table name and ContactId is the field which holds your unique constraint. 3. Now what you're going to do is pass the parameter value into the report via code.
'top of your object...
imports CrystalDecisions.CrystalReports.Engine
imports CrystalDecisions.Shared'load your report
dim myReport as New ReportDocument
with myReport
.Load("myReportTemplate.rpt")
.SetDataSource(myDataSet)
end with'determine which row you want to display
dim drToDisplay as Datarow = myDataSet.Tables("Client").Select("ClientId = " & cstr(currentClientId))'get a reference to the reports parameter field
dim prmClientIdParameter as ParameterFieldDefinition
prmClientIdParameter = myReport.DataDefinition.ParameterFields("ClientId")'create a parameter values collection to set the parameter value
dim valsParClientId as New ParameterValues'create an instance of a parameter value to add to the above parameter values collection
dim valClientId as New ParameterDiscreteValue
valClientId.Value = drToDisplay("ClientId")'add the parameter value to the parameters collection
valsParClientId.Add(valClientId)'set the current value of the reports parameter field
prmClientIdParameter.SetCurrentValues(valsParClientID)'--- code to display/print report etc ---'
that's pretty much it. watch out for spelling or syntactual errors above as i was typing this off of the top of my head just looking at some of my code. i didn't actually type it into the editor. another thing to mention is Brian Bischoff's free online crystal reports e-book. hope this helps.
-jim
-
no problem. :) i actually should have provided some source code here as the crystal objects are not very intuitive. (imho) 1. in your report create a parameter field called "ContactId" 2. in your report right click an empty area in the field explorer. go to "Report", then "Selection Formula" and then finally "Records". This should open the formula workshop. enter a formula for selection criteria like the following:
{Contact.ContactId} = {?ContactId}
where Contact is your table name and ContactId is the field which holds your unique constraint. 3. Now what you're going to do is pass the parameter value into the report via code.
'top of your object...
imports CrystalDecisions.CrystalReports.Engine
imports CrystalDecisions.Shared'load your report
dim myReport as New ReportDocument
with myReport
.Load("myReportTemplate.rpt")
.SetDataSource(myDataSet)
end with'determine which row you want to display
dim drToDisplay as Datarow = myDataSet.Tables("Client").Select("ClientId = " & cstr(currentClientId))'get a reference to the reports parameter field
dim prmClientIdParameter as ParameterFieldDefinition
prmClientIdParameter = myReport.DataDefinition.ParameterFields("ClientId")'create a parameter values collection to set the parameter value
dim valsParClientId as New ParameterValues'create an instance of a parameter value to add to the above parameter values collection
dim valClientId as New ParameterDiscreteValue
valClientId.Value = drToDisplay("ClientId")'add the parameter value to the parameters collection
valsParClientId.Add(valClientId)'set the current value of the reports parameter field
prmClientIdParameter.SetCurrentValues(valsParClientID)'--- code to display/print report etc ---'
that's pretty much it. watch out for spelling or syntactual errors above as i was typing this off of the top of my head just looking at some of my code. i didn't actually type it into the editor. another thing to mention is Brian Bischoff's free online crystal reports e-book. hope this helps.
-jim
This all seems like it would work but I have one problem. I am using a form just for the crystalreportviewer. So I don't have access to my dataset. Do I need to create another dataset on this form, or is there a way around it? Isn't there just a simple way to pass a string, that I already have(contactID), into the report without using the dataset?, then set that string equal to the parameter?, then display that record?:doh: I thought all this would be simple coding but it turned out to be a bigger task than I thought.:( Thanks for that link for the free e-book. I am going to read up on it but I would like to knock out this assignment first. Thanks again for all your help.:) Beginner in ASP.Net and VB.Net
-
This all seems like it would work but I have one problem. I am using a form just for the crystalreportviewer. So I don't have access to my dataset. Do I need to create another dataset on this form, or is there a way around it? Isn't there just a simple way to pass a string, that I already have(contactID), into the report without using the dataset?, then set that string equal to the parameter?, then display that record?:doh: I thought all this would be simple coding but it turned out to be a bigger task than I thought.:( Thanks for that link for the free e-book. I am going to read up on it but I would like to knock out this assignment first. Thanks again for all your help.:) Beginner in ASP.Net and VB.Net
no problem tim. you could just setup a friend property on your display form and pass in a reference to your report document object.
-jim
-
no problem tim. you could just setup a friend property on your display form and pass in a reference to your report document object.
-jim
-
no problem tim. you could just setup a friend property on your display form and pass in a reference to your report document object.
-jim
Thanks Jim,:-D I downloaded the e-book that you recommended and found some great information on what I was looking for. I knew there was something simple I could do. Here is what I did. I created a reportdocument from the toolbox under components and named it report1. I then added this code to my form load event.
Report1.DataDefinition.RecordSelectionFormula = "{MYTABLE.CONTACTID} =" & frmMain.strContactID
CrystalReportViewer1.ReportSource = Report1This works perfect.:) Thanks again for all your help and support;) Beginner in ASP.Net and VB.Net
-
Thanks Jim,:-D I downloaded the e-book that you recommended and found some great information on what I was looking for. I knew there was something simple I could do. Here is what I did. I created a reportdocument from the toolbox under components and named it report1. I then added this code to my form load event.
Report1.DataDefinition.RecordSelectionFormula = "{MYTABLE.CONTACTID} =" & frmMain.strContactID
CrystalReportViewer1.ReportSource = Report1This works perfect.:) Thanks again for all your help and support;) Beginner in ASP.Net and VB.Net
no problem tim. :) take it easy.
-jim