Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. crystal reporting in vb.net

crystal reporting in vb.net

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasequestionlearning
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Britnt7
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • B Britnt7

      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

      J Offline
      J Offline
      Jim Matthews
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • J Jim Matthews

        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

        B Offline
        B Offline
        Britnt7
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • B Britnt7

          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

          J Offline
          J Offline
          Jim Matthews
          wrote on last edited by
          #4

          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

          B 1 Reply Last reply
          0
          • J Jim Matthews

            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

            B Offline
            B Offline
            Britnt7
            wrote on last edited by
            #5

            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

            J 1 Reply Last reply
            0
            • B Britnt7

              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

              J Offline
              J Offline
              Jim Matthews
              wrote on last edited by
              #6

              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

              B 2 Replies Last reply
              0
              • J Jim Matthews

                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

                B Offline
                B Offline
                Britnt7
                wrote on last edited by
                #7

                Jim Matthews wrote: you could just setup a friend property on your display form and pass in a reference to your report document object Sorry to be such a pain but could you show me how do to this?:doh: Thanks so much for all your help and knowledge:) Beginner in ASP.Net and VB.Net

                1 Reply Last reply
                0
                • J Jim Matthews

                  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

                  B Offline
                  B Offline
                  Britnt7
                  wrote on last edited by
                  #8

                  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 = Report1

                  This works perfect.:) Thanks again for all your help and support;) Beginner in ASP.Net and VB.Net

                  J 1 Reply Last reply
                  0
                  • B Britnt7

                    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 = Report1

                    This works perfect.:) Thanks again for all your help and support;) Beginner in ASP.Net and VB.Net

                    J Offline
                    J Offline
                    Jim Matthews
                    wrote on last edited by
                    #9

                    no problem tim. :) take it easy.


                    -jim

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups