Page 1 of 2 12 LastLast
Results 1 to 40 of 46

Thread: Crystal Report In VB.NET

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Arrow Crystal Report In VB.NET

    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
    Last edited by shakti5385; Jun 25th, 2007 at 08:02 AM. Reason: Add Reference list On 14 June 2007 For running Crystal Report

  2. #2
    New Member
    Join Date
    Nov 2006
    Posts
    4

    Re: Crystal Report In VB.NET

    Hello,
    your example is very good.

    So now i have a question: how do to get the sql query that is in my report in vb.net?

    Sorry for my bad english

    billy21

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Arrow Re: Crystal Report In VB.NET

    Just check the following code this is your solution.
    Here both that table1 and the table2 are in the crystal report and passing the query here.
    rpt.SetDataSource(ds)
    Above code filling the data source from the related table.



    VB Code:
    1. Dim connection As New OleDbConnection(funcs.con)'Open New Connection Here
    2.         connection.Open()
    3.         Dim QueryString As String
    4.  
    5.         QueryString = "Select * from Table1 Where ID=" & TextBox1.Text & ""
    6.         Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter(QueryString, connection)
    7.         Dim ds As DataSet = New DataSet()
    8.         Adapter.Fill(ds, "Table1")
    9.  
    10.         QueryString = "Select * from Table2" ' Where ID=" & TextBox1.Text & ""
    11.         Adapter = New OleDbDataAdapter(QueryString, connection)
    12.         ds =  DataSet()
    13.         Adapter.Fill(ds, "Table2")
    14.  
    15.         rpt.Load(Application.StartupPath & "/ReportName.rpt")
    16.         rpt.SetDataSource(ds)
    17.         CrystalReportViewer1.ReportSource = rpt
    Last edited by shakti5385; Dec 7th, 2006 at 04:35 AM.

  4. #4
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: Crystal Report In VB.NET

    Can u send the Sample Code for this ? I really want it.
    I am using .NET 2010 with Windows 7

  5. #5
    New Member
    Join Date
    Feb 2007
    Posts
    4

    Re: Crystal Report In VB.NET

    Dear Shakti5385,

    I'm Impressed with what u have posted but unfortunantly still it doesnt solve my problem, so i thought i'll drop this message that you might be able to help me. So i'll tell you what i am using, i am using VS.NET 2003, MySQL and MySQL Server and I'm using ODBC connection to connect VB.NET and MySQL so the problem with this connection is i cant create datasets with it etc.. here is how i connect:
    Public MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
    "SERVER=localhost;" & _
    "DATABASE=*****;" & _
    "UID=*****;" & _
    "PASSWORD=****;" & _
    "OPTION=3;"
    and sql querries like this:

    Dim MyCommand As New Odbc.OdbcCommand
    Dim fdCom4 As New Odbc.OdbcCommand("SELECT * FROM order ", MyConnection) and
    MyCommand.CommandText = "INSERT INTO blabla SELECT * FROM order " ' when creating network need to add which user name is logged
    MyCommand.Connection = MyConnection


    Please can you help me on how to view crystal report, the code you have published i have tried to amend it but still cant make it work

    Dim CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
    Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
    CrystalReportViewer1.ActiveViewIndex = 0
    ' CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    CrystalReportViewer1.DisplayGroupTree = False
    CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
    CrystalReportViewer1.Location = New System.Drawing.Point(0, 0)
    CrystalReportViewer1.Name = "CrystalReportViewer1"

    Dim MyConnection As New Odbc.OdbcConnection(MyConString)
    Dim MyCommand As New Odbc.OdbcCommand
    Dim fdCom4 As New Odbc.OdbcCommand("SELECT * FROM t_order ", MyConnection)

    'Dim QueryString As String = "select * from TableName" 'Your Query here
    'Dim Connection As New OleDbConnection(funcs.con) 'Your Database Connection Here
    MyConnection.Open()
    Dim Adapter As Odbc.OdbcDataAdapter ' = New Odbc.OdbcDataAdapter(fdCom4, MyConnection) 'Passing the query in the connection
    ' Dim DataSet As DataSet = New DataSet 'DataSet
    ' Adapter.Fill(DataSet)

    Dim DataTable As DataTable = New DataTable 'DataTable

    'DataTable = DataSet.Tables(0) 'filling the datatable here

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


    Please help me,

    regards

    Tosi

  6. #6
    Junior Member Troy Davis's Avatar
    Join Date
    Feb 2007
    Posts
    31

    Re: Crystal Report In VB.NET

    Everything is working beautifully but what if I want my reports to be within my project? How do I set it to find it?

    For Example the following code I know Loads the report form from a folder but I want it to use a resource in my code:

    Code:
    'Report In the report Folder    
    Report.Load(Application.StartupPath & "/Report/" & ReportName & "")

  7. #7
    New Member
    Join Date
    Feb 2007
    Posts
    4

    Re: Crystal Report In VB.NET

    hi there!!

    Do u mean to load to a VB.Net form? if so u need CrystalReport Viewer where u can get on the tool menu.

    regards

    tosi

  8. #8
    Junior Member Troy Davis's Avatar
    Join Date
    Feb 2007
    Posts
    31

    Re: Crystal Report In VB.NET

    No I have the Viewer but I want to set the report it views programmatically without storing the .rpt in a subfolder.

  9. #9
    New Member
    Join Date
    Feb 2007
    Posts
    4

    Re: Crystal Report In VB.NET

    i very much doubt you can do that......................

  10. #10
    Junior Member Troy Davis's Avatar
    Join Date
    Feb 2007
    Posts
    31

    Re: Crystal Report In VB.NET

    Quote Originally Posted by tosi007
    i very much doubt you can do that......................

    hmm see I can add a report to my project but it binds it to a database upon creation the Crystalreport.rpt is in the list of files within my project. Why can't I just programmatically bind the form to the viewer but be able to set the location of the database eachtime it's called?

    You can do this witht the Folder method I just wanted to leave my forms internal to the program structure and not external in a folder to be called.

    But if I have to, the folder method works just fine.

  11. #11
    New Member
    Join Date
    Feb 2007
    Posts
    4

    Re: Crystal Report In VB.NET

    hmm well i have to say that will be a challange for me as well, but anyhow i will post here the way i conneted to database (odbc) and i hope it helps.
    p.s. if you cant connect two tables together you need to do this right click database --> verify database it took me ages to find out and i even lost some hair lol

    I am using mySQL, ODBC driver and VS.NET 2003 which came with Crystal Report.


    vb Code:
    1. Public MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
    2.            "SERVER=localhost;" & _
    3.            "DATABASE=******;" & _
    4.            "UID=*****;" & _
    5.            "PASSWORD=*****;" & _
    6.            "OPTION=3;"
    7.  
    8. Dim myReport As New ReportDocument
    9.         Dim myData As New DataSet
    10.        
    11.         Dim myAdapter As New Odbc.OdbcDataAdapter
    12.         Dim MyConnection As New Odbc.OdbcConnection(MyConString)
    13.         Dim MyCommand As New Odbc.OdbcCommand
    14.         Dim invoice As String
    15.         Dim username As String
    16.         Dim txttotal As String
    17.  
    18.  
    19.         invoice = txtinvoice.Text
    20.  
    21.         Try
    22.             'MyConnection.Open()
    23.             MyConnection.Open()
    24.             'select all from o_mhiring and o_customer table to create an invoice
    25.             MyCommand.CommandText = "SELECT m.mh_name, m.start_date, m.end_date, m.price, m.username, m.invoice_no, m.date, m.total_days, m.g_total, o.c_name, o.c_surname, o.c_add1, o.c_add2, o.c_add3, o.c_pc, o.c_passport, o.c_dlicence, o.c_phone, o.c_email, o.c_invoice_no FROM o_mhiring m INNER JOIN o_customer o  WHERE m.invoice_no = '" & invoice & "' AND m.invoice_no = o.c_invoice_no "
    26.  
    27.             MyCommand.Connection = MyConnection
    28.             myAdapter.SelectCommand = MyCommand
    29.             myAdapter.Fill(myData) 'fill data and load report
    30.             myReport.Load("..\Printmhirings.rpt")
    31.             myReport.Database.Tables(0).SetDataSource(myData.Tables(0))
    32.             MyViewer.ReportSource = myReport
    33.  
    34.         Catch ex As Exception
    35.             MessageBox.Show(ex.Message, "Report could not be created", MessageBoxButtons.OK, MessageBoxIcon.Error)
    36.         End Try
    37.         'close connection
    38.         MyConnection.Close()

  12. #12
    New Member
    Join Date
    Apr 2007
    Posts
    2

    Re: Crystal Report In VB.NET

    i want help abt report in vb2005

  13. #13

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Arrow Re: Crystal Report In VB.NET

    Quote Originally Posted by kripa ostwal
    i want help abt report in vb2005
    Read the article carefully.

  14. #14
    Junior Member Troy Davis's Avatar
    Join Date
    Feb 2007
    Posts
    31

    Re: Crystal Report In VB.NET

    Quote Originally Posted by Troy Davis
    hmm see I can add a report to my project but it binds it to a database upon creation the Crystalreport.rpt is in the list of files within my project. Why can't I just programmatically bind the form to the viewer but be able to set the location of the database eachtime it's called?

    You can do this witht the Folder method I just wanted to leave my forms internal to the program structure and not external in a folder to be called.

    But if I have to, the folder method works just fine.


    As you can see by the areas I have circled, I can create new Crystal reports very easily with the tools to the left. And They are added to my list of Project files to the right.
    But doing it that way binds the report to a fixed database location.

    I can export and save the report then put it into a folder and load it using code just fine then that allows me to provide a different Database location.

    I was hoping there was a way I could use code to provide the viewer with the Report name in my project and also the database location like in the Report.Load statement.

    If you can setup a methode to call a form like frmMain.show() or use a class form or Modules why can't you find a way to bind the reports.
    Last edited by Troy Davis; Apr 7th, 2007 at 04:09 PM.

  15. #15
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Re: Crystal Report In VB.NET

    Quote Originally Posted by kripa ostwal
    i want help abt report in vb2005
    I am facing the same problem too!
    The example on the above that is very good.
    But that cannot be apply in vb 2005, I think that code is for vb 2003

  16. #16
    Junior Member Troy Davis's Avatar
    Join Date
    Feb 2007
    Posts
    31

    Re: Crystal Report In VB.NET

    Quote Originally Posted by newpat
    I am facing the same problem too!
    The example on the above that is very good.
    But that cannot be apply in vb 2005, I think that code is for vb 2003
    I use VB 2005 and the above code works just fine.

  17. #17

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Crystal Report In VB.NET

    I just edit My First Post

  18. #18
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Re: Crystal Report In VB.NET

    I see u use oledb, but I am using odbc, so I think there is the main different

  19. #19
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Crystal Report In VB.NET

    If you are trying to access a report that is a file in your project you can just create an instance of it and then apply tablelogon info like so
    vb.net Code:
    1. Dim Report As New MyReport1
    2. Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
    3.  
    4. ConInfo.ConnectionInfo.UserID = "YORTU_USER"
    5. ConInfo.ConnectionInfo.Password = "YOUR_PASS"
    6. ConInfo.ConnectionInfo.DatabaseName = "YOUR_DATABASE"
    7. For intCounter As Integer = 0 To Report.Database.Tables.Count - 1
    8.     Report.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
    9. Next
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0 • PHP Image Gallery v2.0
    VB 2005
    Find Computers on a network • Simple License Encryption • SQL Server Database Access dll • Use Reflection to Return Crystal ReportDocument • Silently Print PDF • Generic Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost) • MSDN Design Guidelines • API Reference • Inno Setup Compiler • Inno Setup Preprocessor • ISTool - Fairly easy to use GUI for creating inno setup projects • Connection Strings • NAnt -Automated Builds • Cruise Control .NET - Frontend for automated builds

  20. #20
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Re: Crystal Report In VB.NET

    ha, why I use this code and so exception?(extract some from my code
    Code:
    Dim rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument = New FormC Form is my name of report form.
    Dim DataSet As New Data.DataSet()
    rpt.SetDataSource(DataSet)
    exception:
    DataSourceException

  21. #21
    New Member
    Join Date
    May 2007
    Posts
    1

    Re: Crystal Report In VB.NET

    Hello
    Thank you shakti5385 for the code, I found it most helpful.
    But I was wondering if I can use the same code for creating a Crystal Report From an XML file, or is it done through a different method?

    Thank you again
    Best Regards,
    Joody

  22. #22
    Junior Member
    Join Date
    Nov 2005
    Posts
    20

    Re: Crystal Report In VB.NET

    hello am using the following code
    Friend Sub ViewReport(ByVal ReportName As String, ByVal TableName() As String, ByVal QueryString() As String, Optional ByVal [Parameter] As String = "")

    Dim l_objDBManager As DBManager.DBManager
    Me.MdiParent = frmMain
    If Not UBound(TableName).Equals(UBound(QueryString)) Then
    MessageBox.Show("Passed Variable Are Not Correct", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information) : Exit Sub
    End If

    Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument

    Dim CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
    CrystalReportViewer.ActiveViewIndex = 0
    CrystalReportViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    CrystalReportViewer.DisplayGroupTree = False
    CrystalReportViewer.Dock = System.Windows.Forms.DockStyle.Fill
    CrystalReportViewer.Location = New System.Drawing.Point(0, 0)
    CrystalReportViewer.Name = "CrystalReportViewer"
    Dim Adapter As System.Data.SqlClient.SqlDataAdapter
    l_objDBManager = New DBManager.DBManager
    Dim DataSet As New DataSet
    l_objDBManager.SetConn()
    For I As Integer = 0 To UBound(TableName)
    Adapter = l_objDBManager.GetDataAdeptor(QueryString(I))
    Adapter.Fill(DataSet, TableName(I))
    Next

    Report.Load(Application.StartupPath & "/Reports/" & ReportName & "")
    Report.SetDataSource(DataSet)
    'Report.Database.Tables(0).SetDataSource(DataSet.Tables(0))

    If Not [Parameter] = "" Then Report.SetParameterValue(0, [Parameter])
    CrystalReportViewer.ReportSource = Report
    Me.Panel1.Controls.Add(CrystalReportViewer)
    l_objDBManager.DisposeConn()
    End Sub
    but it gives exception on the line Report.SetDataSource(DataSet) that report has no table ....can ny1 help me

  23. #23

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Crystal Report In VB.NET

    Be sure that all the table you are using in the crystal report are passed in the table array in my function.

  24. #24
    Junior Member
    Join Date
    May 2007
    Posts
    18

    Re: Crystal Report In VB.NET

    Ok, this may sound stupid, but I'm still new to VB2005. How do I create a Crystal Report in Report dir?

    I've tried creating the file and moving it, but that doesn't work.

    Thanks,
    Tony

  25. #25
    Junior Member
    Join Date
    May 2007
    Posts
    18

    Re: Crystal Report In VB.NET

    OK, disregard my last post, it was a stupid question.

    Now I have an error I cant figure out.

    Code:
    Type 'CrystalDecisions.Windows.Forms.CrystalReportViewer' is not defined.
    Can someone please help?

    Thanks,
    Tony

  26. #26
    Junior Member Troy Davis's Avatar
    Join Date
    Feb 2007
    Posts
    31

    Wink Re: Crystal Report In VB.NET

    Quote Originally Posted by akernan
    OK, disregard my last post, it was a stupid question.

    Now I have an error I cant figure out.

    Code:
    Type 'CrystalDecisions.Windows.Forms.CrystalReportViewer' is not defined.
    Can someone please help?

    Thanks,
    Tony
    Make sure you added this

    Code:
    Dim CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
    Correctly. If it's not spelled correctly it will dim the wrong variable.

    Can't really tell for sure unless we see your code.

  27. #27
    Junior Member
    Join Date
    May 2007
    Posts
    18

    Re: Crystal Report In VB.NET

    I copied the code directly from the first post.

  28. #28

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: Crystal Report In VB.NET

    Quote Originally Posted by akernan
    I copied the code directly from the first post.
    Just add the reference of crystal report in your project. Project >Click>Add Reference

    Then this will work.

  29. #29
    Junior Member
    Join Date
    May 2007
    Posts
    18

    Re: Crystal Report In VB.NET

    Imanaged to get something to work. Thnks for the replies.

  30. #30

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Crystal Report In VB.NET

    Add the following reference in your project.

    CrystalDecisions.CrystalReport.Engine
    CrystalDecisions.Enterprise.Framework
    CrystalDecisions.Enterprise.infoStore
    CrystalDecisions.ReportSource
    CrystalDecisions.Shared
    CrystalDecisions.Web
    CrystalDecisions.Windows.Forms

  31. #31
    Addicted Member
    Join Date
    May 2006
    Posts
    142

    Re: Crystal Report In VB.NET

    the above code works for crystal reporst. wat if i need to put the database contents in crystal reports viewer? how can i do that?

  32. #32

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Crystal Report In VB.NET

    I am also using crystal reports viewer check it carefully!!

  33. #33
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: Crystal Report In VB.NET

    Hi shakti,
    I am passing the following code in order to automatically logon the database server:
    vb Code:
    1. Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
    2.         ConInfo.ConnectionInfo.UserID = "SCOTT"
    3.         ConInfo.ConnectionInfo.Password = "tiger"
    4.         ConInfo.ConnectionInfo.DatabaseName = "sun"
    5.         Report.Database.Tables(0).ApplyLogOnInfo(ConInfo)

    But it's giving me the following error:

    Invalid report file path.
    I am using adodb connection and i have added all the references.

  34. #34

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Crystal Report In VB.NET

    Please put all the report in a Report folder and set this folder at the application startup path!

  35. #35
    New Member
    Join Date
    Nov 2008
    Posts
    2

    Re: Crystal Report In VB.NET

    Hi this is really informative man!!!!!!!!!!
    I was impressed!!!!!!!!

  36. #36
    New Member
    Join Date
    Jan 2009
    Posts
    2

    Re: Crystal Report In VB.NET

    Excellent sample program!

    I am trying to write an application which displays previously created Crystal Reports for our employees. They have requested the ability to display the SQL query sent to the database. I know this can be viewed when using Crystal itself but we would rather have a way to display it as part of our application. Also, many of our reports are based on a command rather than created through the wizard's table links.

    Any help would be appreciated!

  37. #37

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Crystal Report In VB.NET

    Thanks ranu and John

  38. #38
    New Member
    Join Date
    Jan 2009
    Posts
    2

    Re: Crystal Report In VB.NET

    You cannot view the SQL Query being passed to the database in a windows application. You can however view the SQL Query if you create a web based application.

  39. #39
    New Member
    Join Date
    Oct 2009
    Posts
    2

    Exclamation Re: Crystal Report In VB.NET

    Here Experts here is my codings......



    Dim ds As New DataSet
    ds = New DataSet("LKG")

    Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Working\Sri\My project works\VVB\Vinayaga Vidhya Bhavan\Vinayaga Vidhya Bhavan\bin\Debug\vvb.mdb"
    Dim Connection1 As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConnectionString)
    Dim Command1 As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM LKG")


    Connection1.Open()
    Command1.Connection = Connection1


    Dim OleDbDataAdapter1 As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter

    OleDbDataAdapter1.SelectCommand = Command1
    OleDbDataAdapter1.TableMappings.Add("table", "LKG")

    OleDbDataAdapter1.Fill(ds)
    DataGridView1.DataSource = ds.Tables(0)----> no error
    CrystalReport11.SetDataSource(ds.Tables(0))---> no tables in report
    Public Class Form1
    Public ds As New DataSet1
    Public Sub rep()

    Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Working\Sri\My project works\VVB\Vinayaga Vidhya Bhavan\Vinayaga Vidhya Bhavan\bin\Debug\vvb.mdb")
    cn.Open()
    Dim da As New OleDb.OleDbDataAdapter("select * from LKG", cn)
    da.Fill(ds, "LKG")
    End Sub
    Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
    Call rep()
    Dim obj As New CrystalReport1
    obj.SetDataSource(ds.Tables(0))
    CrystalReportViewer1.ReportSource = obj
    End Sub



    Some one help me please
    what should i do? very urgent!

  40. #40
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,406

    Re: Crystal Report In VB.NET

    Hi:

    Sorry to open the post but i want to try your code and i have this message in this line:

    "Type CrystalReportForm it's not defined"
    I had follow all the steps that you tell in your post...something wrong?

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ReportForm As New CrystalReportForm
    Dim TableName(0) As String
    Dim QueryString(0) As String
    TableName(0) = "Lancamentos" 'Pass The Table That you used in the crystal Report
    QueryString(0) = "SELECT * FROM TableName" ' Pass the Query
    'ReportForm.MdiParent = MainForm 'Pass For Mdi True
    ReportForm.ViewReport("MapaRecapitulativo.rpt", TableName, QueryString, )
    ' You can pass the Parameter Value It is Optional
    ReportForm.Show()

    End Sub

Page 1 of 2 12 LastLast

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