how to connect crystal report with vb.net ?

Answer Posted / himanshu

Public Sub ReportView(ByVal RepoPath As String, Optional
ByVal param As String = "")
Dim ConInfo As New
CrystalDecisions.Shared.TableLogOnInfo
Dim objReport As New
CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim strParamenters As String = param
Dim strParValPair() As String
Dim index As Integer
Dim strVal() As String
Dim Para As String
Dim Val As String

objReport.Load(RepoPath)
If Trim(param) <> "" Then
strParValPair = strParamenters.Split("&")
For index = 0 To UBound(strParValPair)
If InStr(strParValPair(index), "=") > 0 Then
strVal = strParValPair(index).Split("=")
Para = strVal(0)
Val = strVal(1)
objReport.SetParameterValue(Para, Val)
End If
Next
End If
LoginCR(objReport)

For Each Table As
CrystalDecisions.CrystalReports.Engine.Table In
objReport.Database.Tables
ConInfo = Table.LogOnInfo
ConInfo.ConnectionInfo.UserID = "UserName"
ConInfo.ConnectionInfo.Password = "Password"
ConInfo.ConnectionInfo.ServerName = "Your
Server Name"
ConInfo.ConnectionInfo.DatabaseName
= "Attendance"
Table.ApplyLogOnInfo(ConInfo)
Next

FrmCrystalRptViewer.CrystalReportViewer1.DisplayGroupTree =
False

FrmCrystalRptViewer.CrystalReportViewer1.ReportSource =
Nothing

FrmCrystalRptViewer.CrystalReportViewer1.ReportSource =
objReport
FrmCrystalRptViewer.Show()

FrmCrystalRptViewer.CrystalReportViewer1.DisplayGroupTree =
False
FrmCrystalRptViewer.CrystalReportViewer1.Show()
End Sub
Private Sub LoginCR(ByRef CRep As
CrystalDecisions.CrystalReports.Engine.ReportDocument)
Dim LogonInfo As
CrystalDecisions.Shared.TableLogOnInfo
For Each Table As
CrystalDecisions.CrystalReports.Engine.Table In
CRep.Database.Tables
ConInfo = Table.LogOnInfo
ConInfo.ConnectionInfo.UserID = "UserName"
ConInfo.ConnectionInfo.Password = "Password"
ConInfo.ConnectionInfo.ServerName = "Your
Server Name"
ConInfo.ConnectionInfo.DatabaseName
= "Attendance"
Table.ApplyLogOnInfo(LogonInfo)
Next
End Sub

Is This Answer Correct ?    17 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is sorting in vb?

661


What is the diff between vb mdi form and .net mdi form?

727


How do you call a stored procedure in Visual Basic?

754


Explain cls?

758


What is break mode? What are the options to step through code?

746


Define serialization in .net?

803


Explain private assembly?

673


how to deploy vb.net with key and evaluation time? any one can help me?

1944


Which namespace are used for accessing the data?

840


What is a stream in vb.net?

733


What is deep copy?

727


What do you mean by serialization?

725


What is vb.net used for?

723


How would you implement inheritance using vb.net?

691


What are the shared variables?

726