Page 2 of 2 FirstFirst 12
Results 41 to 46 of 46

Thread: Crystal Report In VB.NET

  1. #41
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Question Re: Crystal Report In VB.NET

    i do all you say to do in the post, it does not give me an error but the crystalreport1 that opens is clear, doesnt show nothing how i can correct that?

  2. #42
    New Member
    Join Date
    Jan 2011
    Posts
    1

    Re: Crystal Report In VB.NET

    Report.Load("../CrystalReport1.rpt") 'Report Name Here
    Report.SetDataSource(DataTable)
    CrystalReportViewer1.ReportSource = Report

    if i want to use more than one datasource, how to do that ?

  3. #43
    New Member
    Join Date
    May 2011
    Posts
    7

    Re: Crystal Report In VB.NET

    Hi, I am using Visual Basic 6.0 and not VB.Net. Do you have code I can use to create Crystal report ( Crystal Report 2008) using VB6. I have searched many forums but still have not find code that works with VB 6.0 and Crystal Report 2008.
    Thanks in advance

  4. #44
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    Re: Crystal Report In VB.NET

    Quote Originally Posted by shakti5385 View Post
    Often user get problem for making the report using Vb.Net so here I am providing the simple code for using the report in the VB.NET
    This code simply on the Form Load event, you can change it according to the button also. You have to add just connection and the query according to your project.
    If you do not want to use the SQL query then you can use the selection formulas also
    If any problem related to this code then post me in The PM do not post here Contact me at the PM or post in the reporting section I will check your problem there.


    Step By Step Crystal Report In VB.NET New Code
    1) Add a from in your project Name CrystalReportForm
    2) Add a panel Set the Dock Property To Fill
    3) Add the Code

    VB.NET Code:
    1. Imports System.Data.OleDb
    2. Public Class CrystalReportForm
    3.  
    4.     Public Function GetDataAdeptor(ByVal QueryString As String) As OleDbDataAdapter
    5.         Dim DataAdapter As New OleDbDataAdapter
    6.         Try
    7.             Dim NewConnection As OleDbConnection = OpenNewConnection()
    8.             DataAdapter = New OleDbDataAdapter(QueryString, NewConnection)
    9.             Return DataAdapter
    10.         Catch ex1 As OleDbException
    11.             Throw New Exception("Error Getting The Table", ex1)
    12.         Catch ex As Exception
    13.             Throw New Exception("Error Getting The DataAdapter", ex)
    14.         End Try
    15.  
    16.     End Function
    17.  
    18.     ''' <summary>
    19.     ''' Open Connection Here
    20.     ''' </summary>
    21.     ''' <returns></returns>
    22.     ''' <remarks></remarks>
    23.     Public Function OpenNewConnection() As OleDbConnection
    24.         Dim NewConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=StartUpPath\Database.mdb;Jet OLEDB:Database Password='ShaktiSinghDulawat';")
    25.         Try
    26.             NewConnection.Open()
    27.             Return NewConnection
    28.         Catch ex As Exception
    29.             Throw (ex)
    30.         End Try
    31.     End Function
    32.  
    33.     ''' <summary>
    34.     ''' 1)Add Windows Form Name CrystalReportForm
    35.     ''' 2)Add A Panel Set Dock Proprty To Fill
    36.     ''' </summary>
    37.     ''' <param name="ReportName">Report Name Contain The Name</param>
    38.     ''' <param name="TableName">Table Name In Array</param>
    39.     ''' <param name="QueryString">Query String In Array</param>
    40.     ''' <param name="Parameter">Parameter If Any</param>
    41.     ''' <remarks></remarks>
    42.     '''
    43.  
    44.     Friend Sub ViewReport(ByVal ReportName As String, ByVal TableName() As String, ByVal QueryString() As String, Optional ByVal [Parameter] As String = "")
    45.         Me.MdiParent = MainForm
    46.         If Not UBound(TableName).Equals(UBound(QueryString)) Then MessageBox.Show("Passed Variable Are Not Correct", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information) : Exit Sub
    47.         Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
    48.         Dim CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
    49.         CrystalReportViewer.ActiveViewIndex = 0
    50.         CrystalReportViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    51.         CrystalReportViewer.DisplayGroupTree = False
    52.         CrystalReportViewer.Dock = System.Windows.Forms.DockStyle.Fill
    53.         CrystalReportViewer.Location = New System.Drawing.Point(0, 0)
    54.         CrystalReportViewer.Name = "CrystalReportViewer"
    55.         Dim Adapter As New OleDb.OleDbDataAdapter
    56.         Dim DataSet As New DataSet
    57.         For I As Integer = 0 To UBound(TableName)
    58.             Adapter = GetDataAdeptor(QueryString(I))
    59.             Adapter.Fill(DataSet, TableName(I))
    60.         Next
    61.        'Report In the report Folder
    62.         Report.Load(Application.StartupPath & "/Report/" & ReportName & "")
    63.         Report.SetDataSource(DataSet)
    64.         If Not [Parameter] = "" Then Report.SetParameterValue(0, [Parameter])
    65.         CrystalReportViewer.ReportSource = Report
    66.         Me.Panel1.Controls.Add(CrystalReportViewer)
    67.     End Sub
    68.  
    69. End Class

    How to Call It
    1) Make a Crystal Report and save it in the Report folder at the application startup Path, Just add the Name of the report as CrystalReport1
    2) Make a new form add a command button

    Call This Function for single Table

    VB.NET Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim ReportForm As New CrystalReportForm
    3.         Dim TableName(0) As String
    4.         Dim QueryString(0) As String
    5.         TableName(0) = "TableName" 'Pass The Table That you used in the crystal Report
    6.         QueryString(0) = "SELECT * FROM TableName" ' Pass the Query
    7.         'ReportForm.MdiParent = MainForm 'Pass For Mdi True
    8.         ReportForm.ViewReport("CrystalReport1.rpt", TableName, QueryString, )
    9.         ' You can pass the  Parameter Value It is Optional
    10.         ReportForm.Show()
    11.     End Sub

    For Multiple table Increase the array


    VB.NET Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim ReportForm As New CrystalReportForm
    3.         Dim TableName(1) As String
    4.         Dim QueryString(1) As String
    5.         TableName(0) = "Table1"
    6.         TableName(1) = "Table2"
    7.         QueryString(0) = "SELECT * FROM Table1"
    8.         QueryString(1) = "SELECT * FROM Table2"
    9.         ReportForm.MdiParent = MainForm
    10.         'Here I am Passing the value of Parameter
    11.         ReportForm.ViewReport("CrystalReport1.rpt", TableName, QueryString, "UnRegister")
    12.         ReportForm.Show()
    13.     End Sub
    Still I am Making some modification In the Code as it work successfully I will Tell.

    EDIT :14 June 2007
    Add the following reference in your project.

    VB.NET Code:
    1. CrystalDecisions.CrystalReport.Engine
    2. CrystalDecisions.Enterprise.Framework
    3. CrystalDecisions.Enterprise.infoStore
    4. CrystalDecisions.ReportSource
    5. CrystalDecisions.Shared
    6. CrystalDecisions.Web
    7. CrystalDecisions.Windows.Forms

    Code For The MS Access And The SQL Server 2005 Thanks

    Thanks
    hi shakti bhaya, the report way you mentioned is using oledb connection, while i am working in sqlclient. so can you tell me that what i do now with this?

    1 more thing is that, i want that when i end user call a report so it does not ask for username and password, means that automatically it picks up the username and password.

  5. #45
    New Member
    Join Date
    Sep 2011
    Posts
    1

    Re: Crystal Report In VB.NET

    Hello

    I read your article in the link
    It was great
    Now I have a question
    This gives me an error

    The report has no tables

    This error is on the line below:

    Report.SetDataSource(DataSet)

    In the following form.
    CrystalReportForm.vb

    Please help

    Thanks

    Mr Biroonvand

  6. #46
    New Member
    Join Date
    May 2012
    Posts
    2

    Re: Crystal Report In VB.NET

    a simple sample code to connect vb.net to crystal reports using oledb

    http://vb.net-informations.com/cryst...e_database.htm

    there you can find lot of useful links .

    algor

Page 2 of 2 FirstFirst 12

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