View Single Post
  #1 (permalink)  
Old March 7th, 2007, 12:41 PM
clflyer clflyer is offline
Registered User
Join Date: Jul 2004
Location: Batavia, IL, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to clflyer
Default Deploy CR with Visual Studio 2005 VB.Net

I have a program that I wrote that uses CR for Visual Studio .Net with a report in it. Everything works great on the development PC.

However when I Build the program for deployment to other PCs. It retains the path to the database on my PC. How do I change the path for the report to be something like:
Application.StartupPath & "\Database\Mydatabase.mdb

I've changed the report source to point at it, (crystalReportViewer1.ReportSource = " & Application.StartupPath & "MyReport"), but it still is trying to log on to c:\VB\Myproject\bin\Debug\Mydatabase.mdb.


After many attempts and internet searches I finally found some code that works. I'd like to Credit Imran A Momin with solving my problem. Here is the code:
Imports System.Data.OleDb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class Form1
    Dim rpt As New CrystalReport1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim path1 As String = My.Application.Info.DirectoryPath '' path

        ' OLEDB Connection

        Dim Conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source=|DataDirectory|\General.mdb;")

        ' SQL Command
        Dim Cmd As New OleDbCommand("SELECT * from ACCUM")

        Cmd.CommandType = CommandType.Text '' command type
        Cmd.Connection = Conn '' give connection to command
        Dim adp As New OleDbDataAdapter '' declare adapter
        adp.SelectCommand = Cmd '' select command for adpapter to work on
        Dim ds As New DataSet '' delcare dataset
        adp.Fill(ds, "Crystal") '' fill the dataset through adapter


            ' change the path of the database
            rpt.DataSourceConnections.Item(0).SetConnection("" , "" & path1 & "\General.mdb", False)

        Catch exp As Exception


        End Try

        rpt.SetDataSource(ds) ' set the Dataset for the report
        CRV.ReportSource = rpt ' Load the report into the viewer

    End Sub


End Class
Reply With Quote