on 07-24-2014 5:15 PM
Hello,
I'm hoping my question is simple enough to merit a quick answer. I will lay out the details:
I am writing a WindowsForms App in VB 2012. I have a Crystal Report that points to an Access .mdb at design time in order to get the proper structure and layout correctly.
However, during runtime, I need to point to a completely different .mdb file with the same identical structure. How do I do this? I've tried everything I could find on the net with no success and mostly because the answers are for C programmers. I mean, I can pretty much decipher it, but have gotten zero results.
Thank you for your time.
-Mike
Could you provide a snippet of your code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What part exactly do you mean? I am attempting to use .SetDataSource to specify the database. But, let me see:
-------------------------------------------------------------------------------------------------
Dim meter_report As New meters (where meters is meters.rpt)
CrystalReportViewer1.ReportSource = Nothing
CrystalReportViewer1.RefreshReport()
meter_report.SetDataSource("C:\Users\Public\MORTIZ\mydata.mdb")
CrystalReportViewer1.ReportSource = meter_report
CrystalReportViewer1.Show()
--------------------------------------------------------------------------------------------------
My original mydata,mdb is located on another drive and used solely to help me design the report. During RunTime mydata.mdb will reside in C:\Users\Public\$$$$\mydata.mdb where $$$$ is the user's unique user name.
See if this works for you.
- Bhushan
Senior Engineer
SAP Active Global Support
Follow us on Twitter
Got Enhancement ideas? Try the SAP Idea Place
Getting started and moving ahead with Crystal Reports .NET applications.
From the SAP Crystal Reports .NET API Guide
SetDataSource:
Passes a Recordset or Dataset to the report engine.
E.g.; you are not using the correct APIs. See if Bhushan's idea helps. If not, there is a n umber of other KBAs that may help (search box is in top right corner). I find simple search terms such as 'crystal access how path' give me best results.
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
Follow us on Twitter
I'm fairly sure that I may be forgetting to do something, perhaps even when it comes to adding any references to the solution.
But, honestly, why would it be so hard to simply change the connection to a report? I don't want to OPEN a report by calling and pointing to a physical file location for report.rpt. It's already in my solution and should be able to call it by referencing it as I would any form.
i.e.
Dim Contacts As New Form1
Contacts.Show() ... etc
I should be able to do:
Dim myreport As New report
myreport.Database.File("C:\report.mdb")
myreport.Database.Table("mytable")
That would be logical and as simple as it should be.
Bottom line. I want to change the database location of my Access database that the report uses. I need a clean and detailed step by step instruction on doing so. If I have to add .rpt files to my deployment, I will, but otherwise, I would simply want a straight set of instructions.
I have started a new single form app with just the Viewer on it. I've plugged in the code from the link and fixed the typos.
I need to confirm, which Extensions references should be added to the Solution. I am presuming:
CrystalDecisions.ReportAppServer....
ClientDoc
DataDefModel
ReportDefModel
Controllers
I've gone ahead and done so. But get these messages (warnings):
A reference was created to embedded interop assembly 'CrystalDecisions.ReportAppServer.DataDefModel' because of an indirect reference to that assembly from assembly 'CrystalDecisions.Shared'. Consider changing the 'Embed Interop Types' property on either assembly.
When I run the app, it gives an error when it executes ClientDoc.Open("C:\Crystal\meters.rpt") (Of course that being my report location)
I will continue testing until you respond.
ok. The code needs some small modifications.
I gave it a quick try and here is the InProc RAS SDK code which works for me. Add the assembly references to the app for all those assemblies used in the 'imports' statements in the code.
Imports CrystalDecisions.ReportAppServer.ClientDoc
Imports CrystalDecisions.ReportAppServer.DataDefModel
Imports CrystalDecisions.ReportAppServer.ReportDefModel
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ClientDoc As ISCDClientDocument
Dim logonPb As New CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag()
Dim table_Old As New CrystalDecisions.ReportAppServer.DataDefModel.Table()
Dim table_New As New CrystalDecisions.ReportAppServer.DataDefModel.Table()
'Open the report object to initialize the ReportClientDocument
Dim rd As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
rd.Load("C:\Users\Administrator\Desktop\Report1.rpt")
ClientDoc = rd.ReportClientDocument()
table_old = ClientDoc.Database.Tables(0)
'Clone the original table in the report
table_new = table_old.Clone(True)
' Get the connection information from the report document for the first table in the collection.
logonPb = table_new.ConnectionInfo.Attributes("QE_LogonProperties")
'set the path for new mdb
logonPb.Item("Database Name") = "C:\Users\Administrator\Desktop\New folder\efashion1.mdb"
' Set a new table for the report, set the old table to the new one.
ClientDoc.DatabaseController.SetTableLocation(table_old, table_new)
'view the report
CrystalReportViewer1.ReportSource = rd
End Sub
End Class
Hope this clears the doubts
Thank you both for your help. However, turns out, I figured out a way on my own using one line of code without any Imports at all.
my_report.Database.Table(0).Location = "C:\Crystal\mydatabase.mdb"
my_report = report.rpt which is in my Solution so I created the instance of it using:
Dim my_report As New report
That's all it took. Is this an incorrect approach? Is there a potential bug/issue that is not coming up at this point?
Mr. Ortiz,
You need to read up on and consider using My.Settings to set up and save the user's path to the database. It is not really a CR issue, but a Visual Studio issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
96 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.