How to populate crystal report without parameter fields?

Here I am passing simple SQL record selection query directly from the vb.net application. I have used a simple access database file with a few records to populate the crystal report dynamically.

How to populate crystal report without parameter fields in vb.net
Code: How to populate crystal report without parameter fields in vb.net

        Dim cryRpt As New ReportDocument
        Dim crtableLogoninfo As New TableLogOnInfo

        Dim STR As String = Application.StartupPath
        Dim Filepath As String = STR & "\db.mdb;"
        Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Jet OLEDB:Database Password=123;data source=" & Filepath
        Dim DBcon As New OleDbConnection(constring)
        If (DBcon.State = ConnectionState.Closed) Then DBcon.Open()

        crtableLogoninfo.ConnectionInfo.DatabaseName = STR & "\db.mdb"
        crtableLogoninfo.ConnectionInfo.Password = "123"
        DBcon.Close()
        '****************************************************************************
        cryRpt.Load(Application.StartupPath + "\crpt_contact.rpt")
        For Each CrTables As Table In cryRpt.Database.Tables
            CrTables.ApplyLogOnInfo(crtableLogoninfo)
        Next

        Dim dt As New DataTable
        Dim sqlQuery As String = "select * from tbl_customer_contact where city='" & ComboBox1.Text & "'"
        If (DBcon.State = ConnectionState.Closed) Then DBcon.Open()
        Dim da As New OleDbDataAdapter(sqlQuery, DBcon)
        da.Fill(dt)
        cryRpt.SetDataSource(dt)
        CrystalReportViewer1.ReportSource = cryRpt
        DBcon.Close()

You can also download the complete source code. Click here to start download. I have also added all steps I used to connect my simple database file to populate crystal report without using parameter fields in vb.net

Steps to connect database file in crystal report.
• Right click on Database Fields
• Click on database expert
• In Database Expert dialog box click on Create New Connection
• Click on Database Files node to browse your database file
• Select your database table from the list
• After selecting database file click OK to continue
• Now insert data fields into crystal report

If you liked this post, please like my blog.