how can i connect crystal report to sqlserver with vb.net code ?
-
how can i connect crystal report to sql server with vb.net code ? i don know how to make connection for it. can u give me some example of making crystal report connection?
Read this, it will help you http://www.vbforums.com/showthread.php?p=2686697[^]
Shay Noy
-
how can i connect crystal report to sql server with vb.net code ? i don know how to make connection for it. can u give me some example of making crystal report connection?
If you just want to update your connection settings (dbname / loginid / loginpass) this code will do:
Private Function reconnectreport(ByVal report As ReportDocument, ByVal servernaam As String, ByVal dbnaam As String, ByVal dbLogin As String, ByVal dbPass As String) As ReportDocument
Try
Dim connection As IConnectionInfo
Dim oldServerName As String = report.DataSourceConnections(0).ServerName
Dim newServerName As String = servernaam
Dim oldDatabaseName As String = report.DataSourceConnections(0).DatabaseName
Dim newDatabaseName As String = dbnaam
Dim userID As String = dbLogin
Dim password As String = dbPass
report = report
' Change the server name and database in main reports
For Each connection In report.DataSourceConnections
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
' SetConnection can also be used to set new logon and new database table
report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
End If
Next
' Change the server name and database in subreports
Dim subreport As ReportDocument
For Each subreport In report.Subreports
For Each connection In subreport.DataSourceConnections
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
' SetConnection can also be used to set new logon and new database table
subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
End If
Next
Next
Return report
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function