|
-
Mar 2nd, 2012, 02:53 PM
#1
Thread Starter
New Member
Set Datasource Location to XSD at Runtime
I've done a fair amount of research and testing and have been unable to come up with a solution. Here's my problem:
A product I'm working on has thousands of old reports that use a .ttx file as their datasource. If you right click on the report in Visual Studio and go to Database -> Set Datasource Location, the Current Datasource is something like "C:\ttx folder\somefile.ttx". I add a XSD to the project and then select it under Project Data\ADO.NET Datasets\Crystal_Reports.NewDataSet click "Update" to swap it in for the new ttx.
My question is, is there some way I can do this whole operation programmatically? Most of the information I've found is related to connecting directly to a database and because of the nature of the product the user can not be allowed to do this. I do a SetDataSource(DataSet) where I've populated DataSet myself depending on what the report is. Then I use XSD files to define the datastructure and use that for the Datasource.
-
Mar 2nd, 2012, 09:06 PM
#2
Re: Set Datasource Location to XSD at Runtime
If you designed your report using a dataset, then the report doesn't care where the data comes from as long as the dataset has the correct schema. Like this,
Code:
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\MyTemp\water.accdb")
Dim ds As New DataSet("assesstemp")
Dim da As New OleDbDataAdapter("select * from assesstemp", con)
da.Fill(ds, "assesstemp")
Dim frm As New frmReports
Dim rpt As New rptAssessmentListing
rpt.SetDataSource(ds.Tables("assesstemp"))
frm.CrystalReportViewer1.ReportSource = rpt
frm.ShowDialog()
The report has no idea where you get the data that is in the dataset, so you can choose any database you want. As long as the fields in the datatable match.
-
Mar 2nd, 2012, 10:44 PM
#3
Thread Starter
New Member
Re: Set Datasource Location to XSD at Runtime
The reports weren't designed using a dataset, they were built using TTXs to define the datastructure. I have that code almost verbatim in my project and when I try to run the report via ReportViewer I am prompted with a Login box that asks for username/password for Server: "C:\ttx files\somefile.ttx". The report is using the ttx file as the datasource location. I've tried modifying the report at runtime with:
Code:
customerReport.Database.Tables.Item(0).ApplyLogOnInfo(logOnInfo)
and
Code:
customerReport.DataSourceConnections.Item(0).SetConnection("D:\XSDs\somefile.xsd", "", False)
But these changes make no difference. How can I get the report to stop looking for that ttx file?
To give a better idea of how my code looks it's basically exactly like the sample tutorial VB_Win_Data_DataSets where a helper class fills a dataset and then I use SetDataSource(DataSet).
Last edited by dbcooper; Mar 2nd, 2012 at 10:50 PM.
-
Mar 2nd, 2012, 11:02 PM
#4
Re: Set Datasource Location to XSD at Runtime
Sorry, can't help you. I always design my reports from a dataset that is created by adding a datasource ( a XSD file) to my project. When I choose the reports datasource during design, Project Data\ADO.NET Datasets\mydatasetname.
But at runtime you can use any datasource or file you want to fill the dataset.
-
Mar 3rd, 2012, 11:55 PM
#5
Thread Starter
New Member
Re: Set Datasource Location to XSD at Runtime
Ok thanks anyhow. It's basically just what I described above that I need to figure out how to do pragmatically. The best I've been able to come up with is when I run the report it will display but there will be no data if I just specify a different location for the .ttx using .DataSourceConnections.Item(0).SetConnection().
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
|