|
-
Jan 25th, 2004, 10:46 PM
#1
Thread Starter
Registered User
Setting the path for a crystal report
Ok well I am using crystal reports and I have tried linking a crystal report to a table in an access database manually which works on my pc, the problem is that when I release the app, the database is unlikely to be in the same location on the users pc.
So how do I programmatically set the path of the database used by the crystal report?
-
Jan 25th, 2004, 11:01 PM
#2
PowerPoster
Don't link it to the database. Create a typed dataset, and link it to that. Then in your code, fill the dataset, and use that as the report source.
Much less headaches.
-
Jan 25th, 2004, 11:05 PM
#3
Thread Starter
Registered User
sure i did that too, so how do I change the path of the db for a typed dataset?
-
Jan 26th, 2004, 02:54 AM
#4
You shouldn't need to instead you just fill the typed dataset in the app itself then pass the filled dataset to the report. To change the path for the dataset just change the connectionstring you use for the connection.
-
Jan 26th, 2004, 03:10 AM
#5
Thread Starter
Registered User
Ok that might work Edneeis, do you have the code to change the connection string for a connection created in the server explorer?
-
Jan 26th, 2004, 03:16 AM
#6
You just change it before the fill:
'replace SqlConnection1 with the name of the connection you made at designtime
SqlConnection1.ConnectionString="Your new connectionstring here"
-
Jan 26th, 2004, 03:33 AM
#7
Thread Starter
Registered User
Are you sure that works with connections created with the server explorer?
I tried adding a oledbdataconnection object to the form, but when I tried to create the report, i couldn't use it to create the the dataset and I couldn't choose it from the project data section. So I assume you have to use the server connection object to create the dataset, but I couldn't find the code in the help files :shrug:
-
Jan 26th, 2004, 03:52 AM
#8
Frenzied Member
You may create a dataset from a dataadapter. And a dataadapter needs a dataconnection. You can set the connection string in a way that it is read from config file. Once you have a dataset you may use it to build your report on it. However if you want to avoid datasets, you can easily link your report to a database. Want a sample?
Last edited by Lunatic3; Jan 26th, 2004 at 04:09 AM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 26th, 2004, 05:23 AM
#9
Thread Starter
Registered User
well I tried making my oledb dataset a global dataset and then used this code to try and make it work but to no avail:
oRpt = New CrystalReport1()
oRpt.Load(oRpt.FilePath)
' make sure this line isn't duplicated in the module
Me.CrystalReportViewer1.ReportSource = ds.Tables("tblClients")
the report just comes out without any data.
Lunatic3, I tried linking it to a db directly, but when the user installs the app on their machine the db will be in a different location which makes the report fall over.
-
Jan 26th, 2004, 05:36 AM
#10
Frenzied Member
You are doing things wrong. Read chapter 14 of this book available online.
http://www.crystalreportsbook.com/
And I know what you mean, you can ask the user for the path of the database and other credentials and then apply it to the report. Take a look at this thread. http://www.vbforums.com/showthread.p...hreadid=272958
You can use crystalreportviewer object too and apply the LogonInfo to that.
Last edited by Lunatic3; Jan 26th, 2004 at 10:47 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 26th, 2004, 06:30 AM
#11
Thread Starter
Registered User
Have to register to read chapter 14!
-
Jan 26th, 2004, 01:19 PM
#12
Frenzied Member
Originally posted by Nucleus
Have to register to read chapter 14!
It's free!
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 26th, 2004, 10:43 PM
#13
Thread Starter
Registered User
Well thanks Lunatic, read the chapter and it is easy to follow and concise and covers most things.
I still had problems after reading the chapter though so I thought that I would post the solution for other members
How to write a crystal report bound to an dataset.
The concept is simple. Create a strongly typed dataset to get the xml structure of the dataset, so that you can create the report based on the fields without needing any data. Then at runtime bind the report to the unbound dataset once it is populated.
Create the stongly typed dataset:
1. Use the server explorer to create a connection to the datasource.
2. Add new item to your project and make it a dataset.
3. drag the table(s) etc from the server explorer section onto the dataset.
Creating the report
Then add new item to your project and this time add a crystal report. Use the report expert and for the datasource select project data and then the dataset you just created. Then just follow the prompts and customise it however you want it.
Create the dataviewer on form to display the report.
Add a form to your project and drop on a crystal report viewer object from the bottom of the windows forms toolbox.
Finally Binding the report at runtime
In the form that contains the crystal report viewer, add this code to the load event. This assumes you already have the data you want to display in a dataset called ds.
Dim myReport As New CrystalReport1() ' whatever the name of the report in your project is but it should be CrystalReport1 if it is the first report in your project and you take the default name.
myReport.SetDataSource(ds.Tables(0)) 'to bind it to the first table in the dataset
CrystalReportViewer1.ReportSource = myReport
Troubleshooting:
And that is all there is to it, once you know how! One problem that most examples had was they had this line:
myReport.SetDataSource(ds)
Now even when I only had a single table in the dataset, it still caused an error, so you have to refer to the table in the dataset.
Last edited by Nucleus; Jan 26th, 2004 at 10:54 PM.
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
|