p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Crystal Reports (http://p2p.wrox.com/forumdisplay.php?f=113)
-   -   Deploy CR with Visual Studio 2005 VB.Net (http://p2p.wrox.com/showthread.php?t=55049)

clflyer March 7th, 2007 12:41 PM

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.

Bill

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

        Try

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

        Catch exp As Exception

            MsgBox(exp.Message)

        End Try

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

    End Sub

:)


End Class


All times are GMT -4. The time now is 08:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.