2009-11-09 3 views
0

저는 VS 2005로 작업 중이며 코딩에 Visual Basic을 사용하고 있습니다.Crystal 보고서에서 OLE DB 데이터베이스에 대한 연결 만들기

vb 코드를 사용하여 Crystal Report에 대한 연결 개체를 어떻게 설정합니까?

나는 몇 가지 코드

Dim strcon As String = ConfigurationManager.AppSettings("PhdConnectionString") 
Dim getconn As SqlConnection = New SqlConnection(strcon) 

Dim rpt As ReportDocument = New ReportDocument 

     rpt.Load(Server.MapPath("aspirantCrystalReport.rpt")) 

를 작성했습니다 // 여기 연결 속성을 설정합니다. 어떻게해야합니까?

 CrystalReportViewer1.ReportSource = rpt 
     CrystalReportViewer1.DataBind() 

답변

1

Crystal Reports .NET API를 사용하여이 작업을 수행하지는 않았지만 COM API를 호출하는 VB6로 작성된 작업 코드가 있습니다. API 클래스 및 멤버 이름은 이 아니며과 다를 수 있습니다.

Private Sub SetDataConnections(ByVal oReport As CRAXDRT.Report, ByVal oConnection As ADODB.Connection) 

    ' Do all tables in this report. 
    Dim oTable As CRAXDRT.DatabaseTable 
    For Each oTable In oReport.Database.Tables 
     SetDataConnection oTable, oConnection 
    Next 

    ' Find all subreports and do them too. 
    Dim oSection As CRAXDRT.Section 
    For Each oSection In oReport.Sections 
     Dim oObject As Object 
     For Each oObject In oSection.ReportObjects 
      If TypeOf oObject Is CRAXDRT.SubreportObject Then 
       Dim oSubreportObject As CRAXDRT.SubreportObject 
       Set oSubreportObject = oObject 
       SetDataConnections oSubreportObject.OpenSubreport() 
       Set oSubreportObject = Nothing 
      End If 
     Next 
    Next 

End Sub 

Private Sub SetDataConnection(ByVal oTable As CRAXDRT.DatabaseTable, ByVal oConnection As ADODB.Connection) 

    ' Extract the relevant data from the ADO connection. 
    Dim sServer As String 
    Dim sDatabase As String 
    Dim bTrusted As String 
    Dim sUserName As String 
    Dim sPassword As String 
    Dim nTimeout As Long 
    With oConnection.Properties 
     sServer = .Item("Data Source").Value 
     sDatabase = .Item("Initial Catalog").Value 
     Select Case UCase(.Item("Integrated Security").Value) 
     Case "SSPI", "YES" 
      bTrusted = True 
     Case Else ' "NO", "" 
      bTrusted = False 
     End Select 
     sUserName = .Item("User ID").Value 
     sPassword = .Item("Password").Value 
    End With 
    nTimeout = oConnection.CommandTimeout 

    ' Delete and re-create all connection information. This is the only way of getting it 
    ' to work if the report contains subreports. Changing database drivers on the fly is 
    ' not allowed, so we must re-create the connection using settings appropriate for the 
    ' particular driver involved. 
    Select Case oTable.DllName 
    Case "crdb_ado.dll" 
     With oTable.ConnectionProperties 
      .DeleteAll 
      .Add "Database Type", "OLE DB (ADO)" 
      .Add "Provider", "SQLOLEDB" 
      .Add "Data Source", sServer 
      .Add "Initial Catalog", sDatabase 
      .Add "Integrated Security", bTrusted 
      .Add "User ID", sUserName 
      .Add "Password", sPassword 
      .Add "OLE DB Services", -1 
      .Add "General Timeout", nTimeout 
     End With 
    Case Else 
     ' TODO: Handle other drivers appropriately. 
    End Select 

End Sub 
관련 문제