|
-
Oct 14th, 2005, 09:09 AM
#1
Thread Starter
Member
[RESOLVED] Changing database location from CR 10
Hello again, I need the help of the guru's once again. I have searched the forums looking for an answer to this and couldn't find one so forgive me if I missed it. I have a VB.NET program that uses a crystal report viewer to view a CR I made with CR 10 Professional. When I made the report from within CR 10 Professional I had to set the database location using the wizard. What I am needing to do is have some way where it can find the database from the application startup directory. I was able to change it from within VB.NET but do not know how to do it from within CR 10. All the threads on here that I have found are telling me to add some code within VB.net to connect to my database. I'm not sure how to do that or where to do that. I have a form that has a CR viewer on it to view a report. I have the CR viewer looking in the application startup directory for the report. Now I'm looking for a way for my REPORT to look for the DATBASE. Any help would be great. Thanks!
Last edited by JSteele94; Oct 14th, 2005 at 09:39 AM.
Reason: adding more
-
Oct 16th, 2005, 10:41 AM
#2
Thread Starter
Member
Re: Changing database location from CR 10
I really need help with this PLEASE if anyone can help me with this!!! Then only thing I can think of is if I made a SQL expression from within CR 10 maybe I can tell it from the expression where the database is????? PLEASE HELP!!
-
Oct 17th, 2005, 02:09 AM
#3
Re: Changing database location from CR 10
Why do you need Crystal to figure out where the database is when you can get VB to tell it? Have a look at this thread:
http://www.vbforums.com/showthread.php?t=360605
See post #13
This is VB6, but you should be able to do something similar with VB.Net
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Oct 17th, 2005, 09:24 AM
#4
Thread Starter
Member
Re: Changing database location from CR 10
Thank you for the reply, this looks like what I need. I didn't know I could have VB do it, I was looking in the wrong direction. I'll give this a try and let you know. Thank you very much!
-
Oct 31st, 2005, 10:02 PM
#5
Thread Starter
Member
Re: Changing database location from CR 10
Ok I have been searching for an answer to this for over a month now and I can't find anything!! Someone PLEASE help me with this!!! I'm not looking to change the report source I've already done that, I'm needing VB.NET to pass the database location to my REPORT so my database can be located in the application folder. Please someone HAS to know how to do this!!!!
-
Oct 31st, 2005, 10:40 PM
#6
Re: Changing database location from CR 10
I'm sorry you're still stuck on this. The only way I've ever done this using the Crystal Viewer is either
VB Code:
Dim crDB As CRAXDRT.DatabaseTable
Set crDB = Report.Database.Tables(1)
crDB.Location = App.Path & "\myDB.mdb"
or
VB Code:
Dim crProp As CRAXDRT.ConnectionProperties
Set crProp = Report.Database.Tables(1).ConnectionProperties
crProp.Item("Database Name") = App.Path & "\mydb.mdb"
This is VB6 and Crystal 9, but you would think it would be similar with .Net & V10.
Have you looked at Crystal's KB on the web site?
Good luck.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Oct 31st, 2005, 10:46 PM
#7
Thread Starter
Member
Re: Changing database location from CR 10
 Originally Posted by pnish
I'm sorry you're still stuck on this. The only way I've ever done this using the Crystal Viewer is either
VB Code:
Dim crDB As CRAXDRT.DatabaseTable
Set crDB = Report.Database.Tables(1)
crDB.Location = App.Path & "\myDB.mdb"
or
VB Code:
Dim crProp As CRAXDRT.ConnectionProperties
Set crProp = Report.Database.Tables(1).ConnectionProperties
crProp.Item("Database Name") = App.Path & "\mydb.mdb"
This is VB6 and Crystal 9, but you would think it would be similar with .Net & V10.
Have you looked at Crystal's KB on the web site?
Good luck.
Pete thank you for your reply I think I'm getting close but what do I set "report" to?
 Originally Posted by pnish
Set crProp = Report.Database.Tables(1).ConnectionProperties
.
-
Oct 31st, 2005, 10:47 PM
#8
Thread Starter
Member
Re: Changing database location from CR 10
 Originally Posted by pnish
crProp.Item("Database Name") = App.Path & "\mydb.mdb"[/Highlight]
"Item" is read only, that's the error I'm getting..
-
Oct 31st, 2005, 11:14 PM
#9
Re: Changing database location from CR 10
Try this (or the VB.Net equivalent)
VB Code:
Dim crApp As CRAXDRT.Application
Dim crDB As CRAXDRT.DatabaseTable
Dim Report As CRAXDRT.Report
Set Report = crApp.OpenReport("c:\myreport.rpt")
Set crDB = Report.Database.Tables([b][color=red]n[/color][/b])
crDB.Location = App.Path & "\myDB.mdb"
Report.ViewReport
Note n above. If there is more than one table in your report that needs its location changed, you must specify each one with its ordinal number, eg
VB Code:
Set crDB = Report.Database.Tables(1)
Set crDB = Report.Database.Tables(2)
Set crDB = Report.Database.Tables(3) ..... and so on
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 1st, 2005, 12:06 AM
#10
Thread Starter
Member
Re: Changing database location from CR 10
 Originally Posted by pnish
Try this (or the VB.Net equivalent)
VB Code:
Dim crApp As CRAXDRT.Application
Dim crDB As CRAXDRT.DatabaseTable
Dim Report As CRAXDRT.Report
Set Report = crApp.OpenReport("c:\myreport.rpt")
Set crDB = Report.Database.Tables([b][color=red]n[/color][/b])
crDB.Location = App.Path & "\myDB.mdb"
Report.ViewReport
Note n above. If there is more than one table in your report that needs its location changed, you must specify each one with its ordinal number, eg
VB Code:
Set crDB = Report.Database.Tables(1)
Set crDB = Report.Database.Tables(2)
Set crDB = Report.Database.Tables(3) ..... and so on
Pnish thank you again for the help your providing. I have tried the code and I am getting a weird error now. Here's my code
This is on form load:
VB Code:
Dim crApp As CRAXDRT.Application
Dim crDB As CRAXDRT.DatabaseTable
Dim Report As CRAXDRT.Report
Report = crApp.OpenReport(Application.StartupPath & "\schedule.rpt")
crDB = Report.Database.Tables(0)
crDB.Location = Application.StartupPath & "\agam_data.mdb"
Report.ViewReport()
When I run the program now, and click on the menu item to run my report my program exits with an error that says:
An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll
Additional information: Error creating window handle.
it then points me to the menu item i clicked to open the report:
VB Code:
Private Sub MnuViewSchedules_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuViewSchedules.Click
Me.Cursor = Cursors.WaitCursor
Dim child As New frmschedule()
child.MdiParent = Me
child.Show()
Me.Cursor = Cursors.Default
End Sub
It highlights "child.show()" but I have no clue why.
Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
Last edited by Hack; Nov 1st, 2005 at 02:23 PM.
-
Nov 1st, 2005, 12:15 AM
#11
Re: Changing database location from CR 10
I think that the ordinals start at one, Report.Database.Tables(1)
See if that makes a difference.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 1st, 2005, 12:20 AM
#12
Thread Starter
Member
Re: Changing database location from CR 10
No I changed it to 1 and it still is doing the same.
-
Nov 1st, 2005, 12:29 AM
#13
Re: Changing database location from CR 10
The way I would now tackle the problem would be to start a new project that just contains your report code. I think we're being sidetracked by other un-related issues. It's a pain I know, but it will make it a lot easier from a debugging point of view.
Give it a go and let me know how you get on.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 1st, 2005, 12:49 PM
#14
Thread Starter
Member
Re: Changing database location from CR 10
If I take away your sample code then everything works fine. I've searched on the forms and have found that a lot of people speak of this same problems with mdi forms but no one lists any solutions.
-
Nov 1st, 2005, 04:01 PM
#15
Re: Changing database location from CR 10
I've got VB.Net loaded on a machine somewhere here in the office. I'll see if I can get an example working. I haven't used .Net before so this will be a learning experience for me.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 1st, 2005, 04:11 PM
#16
Thread Starter
Member
Re: Changing database location from CR 10
If you could help me figure this out I couldn't thank you enough! This is the final step I am needing before my program is finished and I have done everything I can! Thank you!
-
Nov 2nd, 2005, 01:13 AM
#17
Re: Changing database location from CR 10
OK. I think I've made some progress. It took me a while to get the hang of VB.Net but I think I could learn to like it. This is what I did.
Added a Crystal Report Viewer control to a form (I used the .Net version of the control which I assume you are too) and a command button. Here's the code
VB Code:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
Dim cr As New ReportDocument
cr.Load("MyReport.rpt", OpenReportMethod.OpenReportByDefault)
cr.Database.Tables(0).Location = "MyDB.mdb"
CrystalReportViewer1.ReportSource = cr
End Sub
And as you can see the table ordinals start at zero, not one as I said previously. Anyway, this method worked without any problems. I didn't try setting up MDI & child forms, I just didn't have the time.
Hope this helps.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 2nd, 2005, 08:44 PM
#18
Thread Starter
Member
-
Nov 2nd, 2005, 08:59 PM
#19
Re: Changing database location from CR 10
Give me 10 minutes while I go and fire up VB.Net and see if I can replicate the error. Back in a flash.........
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 2nd, 2005, 09:23 PM
#20
Re: Changing database location from CR 10
Ok, I get the exact same error if I change Tables(0).Location to anything other than zero.
Do you have more than one database or table referenced on your report?
Crystal uses the Tables(n) index to point to the correct table on the report. So if you had 2 databases, eg Customers.mdb & Sales.mdb and a table from each database, eg [Customer Details] & [Invoices] you need to determine each table's ordinal position on the report. To do this, open your report in Crystal and select Database Expert... from the Database menu.
The right-hand pane will list each database & table referenced by the report. The tables are numbered (internally) sequentially by Crystal, so if for example the Customers DB was listed first, followed by the Sales DB you would reference them like this
VB Code:
cr.Database.Tables(0).Location = "MyNewCustomers.mdb"
cr.Database.Tables(1).Location = "MyNewSales.mdb"
I'm hoping your problem is as simple as that...
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 3rd, 2005, 02:04 AM
#21
Thread Starter
Member
Re: Changing database location from CR 10
I only have 1 database in my report so it should be table(0) but it's not working, I've also tried changing the number a few times but with no luck. I'm beginning to hate crystal reports!!
-
Nov 3rd, 2005, 07:15 PM
#22
Re: Changing database location from CR 10
Is it possible for you to zip up your report & database (or a subset) and post them here? Maybe I'll be able to see what's going on. Very weird.....
I'm not at work until Tuesday but I may be able to check it out over the weekend.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 15th, 2005, 10:57 AM
#23
Thread Starter
Member
Re: Changing database location from CR 10
pnish sorry it took me awhile to get back to you I've been out of town. I can see what I can do to zip it up. Any other ideas I feel we are so close to getting this to work and this is the last thing I need before my program is done and I can't beleive it's this hard to do. In any case thank you very much for all your help!
-
Nov 20th, 2005, 09:15 PM
#24
Thread Starter
Member
-
Nov 20th, 2005, 10:24 PM
#25
Re: [RESOLVED] Changing database location from CR 10
Great stuff!!!!!
Isn't always something obvious (which neither of us picked up).
Cheers
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|