Results 1 to 24 of 24

Thread: Printing in VB.net

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Printing in VB.net

    hi,

    I have a db and i want to print reports from that.. can u please guide me how to do it? can u please give me a sample code.. i want to print a dataset.. is crystal reports a easy way to print? or i have to use print dialogue box?

  2. #2
    Addicted Member
    Join Date
    Mar 2009
    Location
    Denmark
    Posts
    132

    Re: Printing in VB.net

    What is a db?
    Add a PrintDialog and use
    Code:
    .ShowPrintDialog
    Eldrup

  3. #3
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    @Eldrup
    db = database

    @yogesh12
    The best way it's like you said using crystal reports, you can do everything with the gui, just drag and drop a crystalreportviewer to a form, then add a new report, and configure everything... datasource, etc...

  4. #4
    Addicted Member
    Join Date
    Mar 2009
    Location
    Denmark
    Posts
    132

    Re: Printing in VB.net

    Oh, then i cant help here, sorry.
    Eldrup

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    @Eldrup
    db = database

    @yogesh12
    The best way it's like you said using crystal reports, you can do everything with the gui, just drag and drop a crystalreportviewer to a form, then add a new report, and configure everything... datasource, etc...
    can u please give me a piece of code?


    PHP Code:
    Dim da As SqlDataAdapter
            Dim constr 
    As SqlConnection
            constr 
    = New SqlConnection("xxxx")
            
    Dim cmd As SqlCommand
            cmd 
    = New SqlCommand

            da 
    = New SqlDataAdapter("Select * from tbl"constr)
            
    Dim ds As New DataSet
            da
    .Fill(ds)
            
    DataGridView1.DataSource ds.Tables(0)


            
    Dim s As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            s
    .SetDataSource(ds)
            
    CrystalReportViewer1.ReportSource s
            CrystalReportViewer1
    .Refresh()
            
    CrystalReportViewer1.RefreshReport()
            
    CrystalReportViewer1.Show() 
    its not working please correct my code..

  6. #6
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    First, the s var need to be the report document that you must have added to you project, something like CrystalReport1... When you add the report a wizard pop's up to configure the report.

    Then when declaring the s has to be like this:
    VB.NET Code:
    1. Dim s As New CrystalReport1

    And everything should work fine...

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    First, the s var need to be the report document that you must have added to you project, something like CrystalReport1... When you add the report a wizard pop's up to configure the report.

    Then when declaring the s has to be like this:
    VB.NET Code:
    1. Dim s As New CrystalReport1

    And everything should work fine...
    it gives me an error when i try to declare as

    Dim s as new CrystaReport1

    i used reportdocument but it also doesn't works..
    Last edited by yogesh12; Jun 21st, 2009 at 08:03 AM.

  8. #8
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    You've added a new report to your project?

    Right click in the solution, add new item, and add new crystal report.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    You've added a new report to your project?

    Right click in the solution, add new item, and add new crystal report.
    yup added.. condition is same..
    Code:
    Dim constr As SqlConnection
            constr = New SqlConnection("xxxx")
            Dim cmd As SqlCommand
            cmd = New SqlCommand
            Dim da As SqlDataAdapter
            constr.Open()
            da = New SqlDataAdapter("Select name from tbl", constr)
            Dim ds As New DataSet
            da.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)
            Dim s As New CrystalReport1
            s.SetDataSource(ds.Tables(0))
            CrystalReportViewer1.ReportSource = s
            CrystalReportViewer1.Show()
            constr.Close()

  10. #10
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    What's the error message?

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    What's the error message?
    no error msg mate.. added crystal report and done that coding, still i am not able to c any reports in crystal report viewer

  12. #12
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    Are you sure... Maybe you don't have any data in the report...

    You must configure the report, to see anything.

    To test add a textfield to the report and remove this line:
    vb Code:
    1. s.SetDataSource(ds.Tables(0))

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    Are you sure... Maybe you don't have any data in the report...

    You must configure the report, to see anything.

    To test add a textfield to the report and remove this line:
    vb Code:
    1. s.SetDataSource(ds.Tables(0))
    i cant get u man how to configure?

  14. #14
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    When you add a new item, in your case a new report a wizard pop up that let you define the datasource, tables and fields...

    If you don't use the wizard, you can configure it, by selecting the report, and access the Field Explorer (normally in the left near the toolbox).

    If you can't get it, i can create an example project for you...
    Last edited by mickey_pt; Jun 22nd, 2009 at 06:08 AM.

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing in VB.net

    Moved To Reporting

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    When you add a new item, in your case a new report a wizard pop up that let you define the datasource, tables and fields...

    If you don't use the wizard, you can configure it, by selecting the report, and access the Field Explorer (normally in the left near the toolbox).

    If you can't get it, i can create an example project for you...
    please please give....

  17. #17
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    Take a look
    Attached Files Attached Files

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    Take a look
    got error while loading from db Failed to load from Database, DLL "crdbo_xxx.dll cud not be loaded.. mate i got ur point, but how to set the place where i can insert Datasets? and also is it possible to show each records seperately like

    "Emp Name" (in Bold)
    Qualification: "Field 1 " (from DB")
    Work Exp: "Field 2 " (from DB")

    like that?

  19. #19
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    That must be done at design time, you can't do that at runtime, at least with the version that cames with vs...

    1. OPen the report in the main window
    2. Open the tab of the field explorer (if you can't see it, just select crystal reports menu and select Field Explorer)
    3. In the field explorer, right click in the database fields and then database expert, and configure your connection
    4. After this you have a plus sign in the database fields, and you can select fields to insert in the report, drag and drop.
    5. To insert other fields, you can use the Toolbox

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    That must be done at design time, you can't do that at runtime, at least with the version that cames with vs...

    1. OPen the report in the main window
    2. Open the tab of the field explorer (if you can't see it, just select crystal reports menu and select Field Explorer)
    3. In the field explorer, right click in the database fields and then database expert, and configure your connection
    4. After this you have a plus sign in the database fields, and you can select fields to insert in the report, drag and drop.
    5. To insert other fields, you can use the Toolbox
    so i need around 30-45 reports.. do i have to create them all at design time?

  21. #21
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    Yes...

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    Yes...
    anyother easy way apart from that?

  23. #23
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Printing in VB.net

    I don't think there's an easy way to do that...

    Just think, at runtime, how do you place the items in the report, and format the texts, etc.

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    429

    Re: Printing in VB.net

    Quote Originally Posted by mickey_pt View Post
    I don't think there's an easy way to do that...

    Just think, at runtime, how do you place the items in the report, and format the texts, etc.
    is it possible in any other way? to print dataset with some kinda order?

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