Reputation: 1034
I have a report whose datasource is sql server.I want the report to be able to pick different database dynamically so that if I call it using vb app it can pick a database.I was thinking database and password being got from xml document. Please help other methods are welcome.Thanks.
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CrystalReportViewer1.ReportSource = ("C:\Users\Martin\Desktop\working\EMPLOYEES.rpt")
CrystalReportViewer1.Show()
End Sub
my vb code that calls the report above.
Upvotes: 0
Views: 980
Reputation: 1034
solution`Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Imports System.Xml
Public Class Form2
Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
Me.Left = 0
Me.Top = 0
Me.Height = 10000
Me.Width = 18408
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim crReportDocument As New ReportDocument()
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
'Dim reader As XmlTextReader = New XmlTextReader("C:\Users\Martin\Desktop\About2Go_H.A.M\working\db.xml")
Dim document As XDocument = XDocument.Load("c:\Users\Martin\Desktop\About2Go_H.A.M\working\db.xml")
Dim title = From t In document.Descendants("ServerName") Select t.Value
Dim ServerName1 = title.First()
Dim title2 = From t In document.Descendants("DatabaseName") Select t.Value
Dim DatabaseName1 = title2.First()
Dim title3 = From t In document.Descendants("UserID") Select t.Value
Dim UserID1 = title3.First()
Dim title4 = From t In document.Descendants("Password") Select t.Value
Dim password1 = title4.First()
crReportDocument.Load("C:\Users\Martin\Desktop\About2Go_H.A.M\working\EMPLOYEES2.rpt")
CrystalReportViewer1.ReportSource = crReportDocument
CrTables = crReportDocument.Database.Tables
Dim crLoc As String
crLoc = UserID1 & ".dbo"
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
'Read MachineName\InstanceName,Database details from User interface
'and load them into crConnectionInfo object
crConnectionInfo.ServerName = ServerName1
crConnectionInfo.DatabaseName = DatabaseName1
crConnectionInfo.UserID = UserID1
crConnectionInfo.Password = password1
crConnectionInfo.IntegratedSecurity = False
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)
Next
crReportDocument.ReportOptions.EnableSaveDataWithReport = False
'Refresh the ReportViewer Object
CrystalReportViewer1.RefreshReport()
'Bind the ReportDocument to ReportViewer Object
CrystalReportViewer1.ReportSource = crReportDocument
End Sub
End Class`
Upvotes: 1