Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how can i connect crystal report to sqlserver with vb.net code ?

how can i connect crystal report to sqlserver with vb.net code ?

Scheduled Pinned Locked Moved Visual Basic
tutorialquestioncsharpdatabase
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xingselex
    wrote on last edited by
    #1

    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?

    H T 2 Replies Last reply
    0
    • X xingselex

      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?

      H Offline
      H Offline
      helelark123
      wrote on last edited by
      #2

      Read this, it will help you http://www.vbforums.com/showthread.php?p=2686697[^]

      Shay Noy

      1 Reply Last reply
      0
      • X xingselex

        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?

        T Offline
        T Offline
        Tom Deketelaere
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups