Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Posts
    4

    Red face Unanswered: Passing table to Crystal reports

    Hai friend,

    Please let know how to pass a table to crystal Reports ?

    dim repx as new report1
    repx.setreportsource(datatable1)

    I have used the above code. But I received a Database login dialog box.

    I am using Access databace and Admin as username.

    Please also let me know how add the the fields of the table passing to Crystal report when desing a report form ?

  2. #2
    Join Date
    Jul 2005
    Posts
    50
    As in my other post:

    In .NET, are you using the SetDataSource method to bind to a DataSet or a DataTable? Make sure you are binding to the DataSet, and not specifying a DataTable.

    Quote Originally Posted by bennykavil
    Hai friend,

    Please let know how to pass a table to crystal Reports ?

    dim repx as new report1
    repx.setreportsource(datatable1)

    I have used the above code. But I received a Database login dialog box.

    I am using Access databace and Admin as username.

    Please also let me know how add the the fields of the table passing to Crystal report when desing a report form ?

  3. #3
    Join Date
    Jul 2005
    Posts
    50
    OK ... I wrote and and tested some code for you that demonstrates what we call the "Push" method of populating a Crystal Report. I will make comments as I go, so bear with me if I overly describe what's going on:

    Code:
    ' Above the Form class, my Imports are:
    
    Imports System.Data.OleDb
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    
                ' In the Form_Load (with a Crys Rpt viewer dragged onto the form) I write:
    
            Try
                ' The connection is to the sample database MS ships with Ms Access
                Dim objConn As New OleDbConnection _
                    ("Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;" & _
                    "Data Source=C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb")
                ' Open the database connection
                objConn.Open()
                'Instantiate an OLE Data Adapter and pass the desired SQL 
                Dim objAdapter As New OleDbDataAdapter("SELECT * FROM Products", objConn)
                ' Create a Dataset Object
                Dim objDataSet As New DataSet
                ' Fill the Dataset with the Data specified by the OLE Data Adapter
                objAdapter.Fill(objDataSet)
    
                ' Create a Report Object
                Dim oReport As New ReportDocument
                ' Make sure you have a Crystal Report already created
                Dim sRptPath As String = "C:\Documents and Settings\Michael\My Documents\Visual Studio Projects\PassTableToCrystalReports\bin\Emtpy.rpt"
                ' UnRemark this code ONCE  so you can create an xml schema to serve as a Datasource connection for you Crystal Report
                ' Open the blank report and do the "SelectDataSoruce" action in the Field Explorer by right-clicking the top of the tree for the Database Fields 
                ' Select ADO.Net (XML) as the connection.
                ' You will now have datafields (empty of data, though) that follow the schema created in the xml 
                ' Place the fields you want to display onto your report and close it
    ----- >>>>  dsAddresses.WriteXmlSchema("C:\Documents and Settings\Michael\My Documents\Visual Studio Projects\PassTableToCrystalReports\bin\Addresses.xml")
                ' Stop .NET, remark out the above red section and re-run the code
                ' Load the Report into your Report Object 
                oReport.Load(sRptPath)
                ' Set the Dataset as the Datasource for the Report Object
                oReport.SetDataSource(objDataSet)
                ' Specify the Report object as the Source for the Report Viewer
                CrystalReportViewer1.ReportSource = oReport
                
            Catch ex As Exception
                'Capture any error messages and handle them
                Dim sErrorMsg As String
                Dim sInnerErrorMsg As String
    
                sErrorMsg = ex.Message
                If Not ex.InnerException.Message Is Nothing Then
                    sInnerErrorMsg = ex.InnerException.Message.ToString
                End If
            End Try
    Last edited by mlbuie; 04-20-06 at 16:34.

Posting Permissions

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