Results 1 to 4 of 4

Thread: dynamic crystal report with runtime generated dataset

  1. #1

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    dynamic crystal report with runtime generated dataset

    Hi! I have to print a report of a runtime generated dataset. The user can select between 5 fields to report. E.g.: If he choose to print the price item, then the select query will have to onjoin the tbl_price. I need to know how to tell what field to print at runtime, and I just CAN'T FIND IT!!!!!! I googled all the web! msdn, newsgroup, yahoo, vbforums, i cant find it anywhere, canm anyone help me with this one, I'm desperate since the deadline is at the end of the week, and i been struggling with this for more than a week!!! I feel like I'm wastin my time, and i really don't have any to waste! anyhelp really appreciated!
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  2. #2
    New Member
    Join Date
    Aug 2005
    Posts
    10

    Re: dynamic crystal report with runtime generated dataset

    If you are using VB.Net then you may follow these steps

    1. Add a Form in your application.
    2. Create Data Adapter, Connection during runtime in that form
    3. Generate a Dataset during design time from Data Adapter
    4. Create the .rpt file from scratch and make it point to the Dataset that you created, remember not from the database direct.
    5. Place a Crystal report viewer control on that form.

    Your next move is to add reference to System.XML.dll
    Depending on the database you are using you must import the required namespaces. Here I'll show you with MS-Access

    In the first line of your Form
    VB Code:
    1. Imports System.Data.OleDb
    Next step Runtime data population
    VB Code:
    1. private sub GetDataForReport()
    2. dim myCon as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=[your database file location] ")
    3. dim myCMD as New OleDbCommand()
    4. myCMD.Connection=myCon
    5. myCMD.CommandType=CommandType.Text
    6. myCMD.CommandText="Select Statement"
    7.  
    8. dim myDA as OleDbDataAdapter()
    9. myDA.SelectCommand=myCMD
    10. dim myDS as New [Your Datasetname in the Form]
    11. myDA.Fill(myDS,"TableName")
    12. dim myRPT as new [You .rpt Name]
    13. myRPT.SetDataSource(myDS)
    14. [Your Crystal report viewer].ReportSource=myRPT

    And you are done. Enjoy...

    In the name of Jesus Christ, peace be with you.....God loves you.
    If this work please rate it.

  3. #3

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Re: dynamic crystal report with runtime generated dataset

    Hi Suan, thank you for your help! I still have some problem. I did what you said, but I have a blank report. Obviously, I must be missing something!

    Quote Originally Posted by Suan Ngaihte
    4. Create the .rpt file from scratch and make it point to the Dataset that you created, remember not from the database direct.
    - Does the dataset I point the report to have to be populated, or just a empty dataset??
    - Do I have to drag the field I want on the report? Because the field printed will depend of the User's choice (he can choose whether to print these fields—'latin name', 'family', 'format', price', 'guarantee'— he can print them all or just 1 or them.)



    here is the code:

    VB Code:
    1. Private Sub populateItemListing()
    2.         Dim cnnListing As New SqlConnection(STR_SQL_CONNECTION_STRING)
    3.         Dim cmmListing As New SqlCommand
    4.         Dim dadListing As New SqlDataAdapter
    5.         Dim dstListing As New DataSet1
    6.         Dim rptListing As New rptPlant
    7.  
    8.         Try
    9.  
    10.  
    11.             cmmListing.Connection = cnnListing
    12.             cmmListing.CommandType = CommandType.Text
    13.             cmmListing.CommandText = "SELECT latin_name FROM tbl_items WHERE hard_good = 0"
    14.  
    15.  
    16.             dadListing.SelectCommand = cmmListing
    17.             dadListing.Fill(dstListing, "item")
    18.  
    19.             rptListing.SetDataSource(dstListing)
    20.             list.reportList.ReportSource = rptListing
    21.  
    22.         Catch ex As Exception
    23.             MessageBox.Show(ex.Message)
    24.         Finally
    25.  
    26.             list.Show()
    27.             list.MdiParent = Me
    28.         End Try

    Thank you! Any help appreciated!
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  4. #4
    New Member
    Join Date
    Aug 2005
    Posts
    10

    Re: dynamic crystal report with runtime generated dataset

    1. Do you create the report using dataset fields? You must...
    2. Do you call the "populateItemListing()" method in the form load event? You must do....
    3. Do your connection string point to the correct path? It must.

    Check out....man.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width