Results 1 to 18 of 18

Thread: [RESOLVED] crystal reports and VB 2005

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    82

    Resolved [RESOLVED] crystal reports and VB 2005

    hi everyone,

    i'm trying to do reporting with crystal reports but i dont seem to be finding anything useful on the internet. can any of you point me in the correct direction? the syntax in VB2005 is so different from VB6.0.

    thanks in advance.

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

    Re: crystal reports and VB 2005

    Hi
    I Make a simple code for printing data in the crystal report just read each and every line in the code and check it.
    Remember This code simply on the Form Load event.
    Test this code
    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 here



    VB Code:
    1. Dim CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
    2.         Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
    3.         CrystalReportViewer1.ActiveViewIndex = 0
    4.         CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    5.         CrystalReportViewer1.DisplayGroupTree = False
    6.         CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
    7.         CrystalReportViewer1.Location = New System.Drawing.Point(0, 0)
    8.         CrystalReportViewer1.Name = "CrystalReportViewer1"
    9.  
    10.         Dim QueryString As String = "select * from TableName" 'Your Query here
    11.         Dim Connection As New OleDbConnection(funcs.con) 'Your Database Connection Here
    12.         Connection.Open()
    13.  
    14.         Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter(querystring, connection)'Passing the query in the connection
    15.         Dim DataSet As DataSet = New DataSet() 'DataSet
    16.         Adapter.Fill(DataSet)
    17.         Dim DataTable As DataTable = New DataTable 'DataTable
    18.         DataTable = DataSet.Tables(0) 'filling the datatable here
    19.         Report.Load(Application.StartupPath & "/ReportName.rpt") 'Report Name Here
    20.         Report.SetDataSource(DataTable)
    21.         CrystalReportViewer1.ReportSource = Report

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    82

    Re: crystal reports and VB 2005

    thank you. i'll give it a try when i get back.

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: crystal reports and VB 2005

    I can't wait Until the tags are fixed!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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

    Question Re: crystal reports and VB 2005

    Quote Originally Posted by Mark Gambo
    I can't wait Until the tags are fixed!
    Which Tags

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: crystal reports and VB 2005

    Quote Originally Posted by shakti5385
    Which Tags
    The [VBCODE] your code goes in here [/VBCODE] Tags
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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

    Re: crystal reports and VB 2005

    Quote Originally Posted by Mark Gambo
    The [VBCODE] your code goes in here [/VBCODE] Tags
    I use that code but why that are not working i have not any idea

  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: crystal reports and VB 2005

    Quote Originally Posted by shakti5385
    I use that code but why that are not working i have not any idea

    They upgraded the Fourm Software, take a look at this LINK. According to the Post the tags should be working by today.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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

    Re: crystal reports and VB 2005

    Ic

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    82

    Re: crystal reports and VB 2005

    thank you everyone and sorry for the late reply. what happens if i want to preview the report in crystal report itself? i cant seem to find the revelant codes.

  11. #11
    Lively Member
    Join Date
    Aug 2006
    Location
    Sweden
    Posts
    114

    Re: crystal reports and VB 2005

    Please HELP

    I am trying to get this code to work and the only thing I get is a empty form:-(

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2.         Dim CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
    3.         Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
    4.         CrystalReportViewer1.ActiveViewIndex = 0
    5.         CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    6.         CrystalReportViewer1.DisplayGroupTree = False
    7.         CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
    8.         CrystalReportViewer1.Location = New System.Drawing.Point(0, 0)
    9.         CrystalReportViewer1.Name = "CrystalReportViewer"
    10.  
    11.         Dim QueryString As String = "select * from Companies" 'Your Query here
    12.         Dim Connection As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=c:\alpha.mdf;Integrated Security=True;User Instance=True") 'Your Database Connection Here
    13.         Connection.Open()
    14.  
    15.         Dim Adapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(QueryString, Connection) 'Passing the query in the connection
    16.         Dim DataSet As DataSet = New DataSet() 'DataSet
    17.         Adapter.Fill(DataSet)
    18.         Dim DataTable As DataTable = New DataTable 'DataTable
    19.         DataTable = DataSet.Tables(0) 'filling the datatable here
    20.         Report.Load(Application.StartupPath & "/CrystalReport1.rpt") 'Report Name Here
    21.         Report.SetDataSource(DataTable)
    22.     End Sub

    Anybody having a sample on how to use Crystal in VB.net?

    Bert

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

    Re: crystal reports and VB 2005

    Read Cr in VB.NET At my signature Last Post

  13. #13
    Lively Member
    Join Date
    Aug 2006
    Location
    Sweden
    Posts
    114

    Re: crystal reports and VB 2005

    Well, that is what I have been doing. If you look on my code will you see that its from your "Cr in VB.Net

    Bert

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

    Question Re: crystal reports and VB 2005

    Quote Originally Posted by AlphaOne
    Well, that is what I have been doing. If you look on my code will you see that its from your "Cr in VB.Net

    Bert
    See Again The Last Post There is New Code I Pot Recently, If Any Problem Then Tell

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    82

    Re: crystal reports and VB 2005

    thank you so much shakti for the examples. they were great! i was able to load crystal report through vb without any difficulties. however, i DO have difficulties trying to pass parameters into the report.

    i start out doing the easy parts first:

    1. creat a form called CrystalReportForm with the following function:

    Friend Sub ViewReport(ByVal ReportName As String, ByVal TableName() As String, ByVal QueryString() As String, Optional ByVal [Parameter] As String = "")
    Me.MdiParent = MainForm
    If Not UBound(TableName).Equals(UBound(QueryString)) Then MessageBox.Show("Passed Variable Are Not Correct", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information) : Exit Sub
    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 New OleDb.OleDbDataAdapter
    Dim DataSet As New DataSet
    For I As Integer = 0 To UBound(TableName)
    Adapter = GetDataAdeptor(QueryString(I))
    Adapter.Fill(DataSet, TableName(I))
    Next
    'Report In the report Folder
    Report.Load(Application.StartupPath & "/Report/" & ReportName & "")
    Report.SetDataSource(DataSet)
    If Not [Parameter] = "" Then Report.SetParameterValue(0, [Parameter])
    CrystalReportViewer.ReportSource = Report
    Me.Panel1.Controls.Add(CrystalReportViewer)
    End Sub

    2. i then create another form with a simple button and code (no tables no queries yet) just to test if it works. i pasted this code into the buttonand it works.

    Dim ReportForm As New CrystalReportForm
    Dim TableName(0) As String
    Dim QueryString(0) As String
    TableName(0) = "TableName"
    QueryString(0) = "SELECT * FROM TableName"
    'ReportForm.MdiParent = MainForm 'Pass For Mdi True
    ReportForm.ViewReport("CrystalReport1.rpt", TableName, QueryString, )
    ' You can pass the Parameter Value It is Optional
    ReportForm.Show()

    3. i then read about parameter passing and wanted to try it out so i added the following into the button control as well.

    Imports CrystalDecisions.CrystalReports.Engine

    then under the button:

    Dim crParameterDiscreteValue As ParameterDiscreteValue
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldLocation As ParameterFieldDefinition
    Dim crParameterValues As ParameterValues

    crParameterFieldDefinitions = report.DataDefinition.ParameterFields
    crParameterFieldLocation = crParameterFieldDefinitions.Item("@ParameterName1")
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    crParameterDiscreteValue.Value = "Parameter1Value"
    crParameterValues.Add(crParameterDiscreteValue)
    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)

    however for the ParameterDiscretevalue and ParameterValues i get the error 'type not defined'.

    and for the crParameterFieldDefinitions = report.DataDefinition.ParameterFields i get an error message 'DataDefinition is not a member of Reportname.crystalreport'.

    what am i doing wrong here?? is there something i left out?

    best regards and happy new year.

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

    Re: crystal reports and VB 2005

    . i then read about parameter passing and wanted to try it out so i added the following into the button control as well.

    Imports CrystalDecisions.CrystalReports.Engine

    then under the button:

    Dim crParameterDiscreteValue As ParameterDiscreteValue
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldLocation As ParameterFieldDefinition
    Dim crParameterValues As ParameterValues

    crParameterFieldDefinitions = report.DataDefinition.ParameterFields
    crParameterFieldLocation = crParameterFieldDefinitions.Item("@ParameterName1")
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    crParameterDiscreteValue.Value = "Parameter1Value"
    crParameterValues.Add(crParameterDiscreteValue)
    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)

    however for the ParameterDiscretevalue and ParameterValues i get the error 'type not defined'.

    and for the crParameterFieldDefinitions = report.DataDefinition.ParameterFields i get an error message 'DataDefinition is not a member of Reportname.crystalreport'.
    Do not do this
    Pass the value of parameter in the funciton and for multiple parameter you can use array of parameter also.
    If any need to change the funciton then change it.
    Pass the parameter as I mention

    VB Code:
    1. If Not [Parameter] = "" Then Report.SetParameterValue("ParameterName", [Parameter])

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    82

    Re: crystal reports and VB 2005

    thank you so very much. that did the trick!

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

    Thumbs up Re: crystal reports and VB 2005

    Quote Originally Posted by gp04lch
    thank you so very much. that did the trick!
    Your Welcome
    Get the solution then please go to the thread tool menu and click on the Resolved this thread, so people know that it is resolved.

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