Results 1 to 9 of 9

Thread: [RESOLVED] Database ,Crystal Reports, anb Vb.Net 2005

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    Resolved [RESOLVED] Database ,Crystal Reports, anb Vb.Net 2005

    Hi ,

    I have a report, that thake the information about c:\myprogram\data.mdb ,
    the problem, is that the user can choice another database ,but always my report ,that data from c:\myprogram\data.mdb.

    All that i can do is change from ,click crystalreport1.rpt, after ,right button ,data base ,and choice database.

    But how i can change from code?

    Thanks

  2. #2
    Junior Member
    Join Date
    Sep 2006
    Posts
    18

    Re: Database ,Crystal Reports, anb Vb.Net 2005

    Use
    Cr.Datasource with Data Controls on From or
    Cr.Connect with ODBC Connection String

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    Re: Database ,Crystal Reports, anb Vb.Net 2005

    Sorry but i can't find it.
    In my program ,i have a report called crystalreport1.rpt ,and if in my form code ,i put crystalreport1. enable evenlog ,equals and referenceequals ;and if i put crystalreport11. i can see clone,close ,database ...

    but anywhere Datasource or connect ,how i can fix it?

    Thanks

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    Re: Database ,Crystal Reports, anb Vb.Net 2005

    Hi ,does anybody can help me?

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Database ,Crystal Reports, anb Vb.Net 2005

    This is waht we use (VB 2005 and CR11):
    VB Code:
    1. Public strReport As String
    2.     Public strSelect As String
    3.     Public param As String
    4.  
    5.  
    6.    Private Sub frmReportView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.         ViewReport(strReport, strSelect, param)
    8.     End Sub
    9.  
    10.  
    11.    Friend Function ViewReport(ByVal sReportName As String, Optional ByVal sSelectionFormula As String = "", Optional ByVal param As String = "") As Boolean
    12.  
    13.         Dim intCounter As Integer
    14.         Dim intCounter1 As Integer
    15.         Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    16.  
    17.         Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
    18.  
    19.         Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
    20.         Dim currValue As CrystalDecisions.Shared.ParameterValues
    21.         Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
    22.         Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    23.  
    24.         Dim strParamenters As String = param
    25.         Dim strParValPair() As String
    26.         Dim strVal() As String
    27.         Dim index As Integer
    28.  
    29.         Try
    30.             Me.Cursor = Cursors.WaitCursor
    31.             objReport.Load(Application.StartupPath & "\" & strReport)
    32.  
    33.             intCounter = objReport.DataDefinition.ParameterFields.Count
    34.             If intCounter = 1 Then
    35.                 If InStr(objReport.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then
    36.                     intCounter = 0
    37.                 End If
    38.             End If
    39.  
    40.  
    41.             If intCounter > 0 And Trim(param) <> "" Then
    42.  
    43.                 strParValPair = strParamenters.Split("&")
    44.                 For index = 0 To UBound(strParValPair)
    45.                     If InStr(strParValPair(index), "=") > 0 Then
    46.                         strVal = strParValPair(index).Split("=")
    47.                         paraValue.Value = strVal(1)
    48.                         currValue = objReport.DataDefinition.ParameterFields(strVal(0)).CurrentValues
    49.                         currValue.Add(paraValue)
    50.                         objReport.DataDefinition.ParameterFields(strVal(0)).ApplyCurrentValues(currValue)
    51.                     End If
    52.                 Next
    53.             End If
    54.  
    55.  
    56.  
    57.             ConInfo.ConnectionInfo.UserID = "HAPPY"
    58.             ConInfo.ConnectionInfo.Password = "GILMORE"
    59.             ConInfo.ConnectionInfo.DatabaseName = "XMEN"
    60.  
    61.             For intCounter = 0 To objReport.Database.Tables.Count - 1
    62.                 objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
    63.             Next
    64.  
    65.  
    66.  
    67.             For index = 0 To objReport.ReportDefinition.Sections.Count - 1
    68.                 For intCounter = 0 To objReport.ReportDefinition.Sections(index).ReportObjects.Count - 1
    69.                     With objReport.ReportDefinition.Sections(index)
    70.                         If .ReportObjects(intCounter).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
    71.                             mySubReportObject = CType(.ReportObjects(intCounter), CrystalDecisions.CrystalReports.Engine.SubreportObject)
    72.                             mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
    73.                             For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count - 1
    74.                                 mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo)
    75.                             Next
    76.                         End If
    77.                     End With
    78.                 Next
    79.             Next
    80.  
    81.             If sSelectionFormula.Length > 0 Then
    82.                 objReport.RecordSelectionFormula = sSelectionFormula
    83.             End If
    84.  
    85.             crViewer.ReportSource = Nothing
    86.             crViewer.ReportSource = objReport
    87.             crViewer.Zoom(1)
    88.  
    89.             crViewer.Show()
    90.  
    91.             Application.DoEvents()
    92.  
    93.             Me.Text = sReportName
    94.             MyBase.Visible = True
    95.             Me.BringToFront()
    96.  
    97.             Return True
    98.  
    99.         Catch ex As System.Exception
    100.             MsgBox(ex.Message)
    101.         Finally
    102.             Me.Cursor = Cursors.Default
    103.         End Try
    104.  
    105.     End Function
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    Re: Database ,Crystal Reports, anb Vb.Net 2005

    Hi ,firts thanks for your help,

    Some questions:

    1)
    Public strReport As String --> Is the name of my report file, ej: Crytal.rpt
    Public strSelect As String --> String sql ,ej: select * from table
    Public param As String ---> ???

    2)
    My database ,doesn't have password ,so what i have to put here?

    ConInfo.ConnectionInfo.UserID = "HAPPY"
    ConInfo.ConnectionInfo.Password = "GILMORE"
    ConInfo.ConnectionInfo.DatabaseName = "XMEN"

    3)
    I tyed viewrerport ("C:\name.rpt") and i get "Can't load this report") ,what's wrong?

    ----------

    Thanks a lot for your help again

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Database ,Crystal Reports, anb Vb.Net 2005

    Public strReport As String --> Is the name of my report file, ej: Crytal.rpt Yes
    Public strSelect As String --> String sql ,ej: select * from table This is a condition statement (report selection cretieria for us)
    Public param As String ---> ??? Used for parameters in a report.

    Just don't use the username and password fields. The database name would be the full path to your db.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    Re: Database ,Crystal Reports, anb Vb.Net 2005

    thanks ,works fine !!!!!!

  9. #9
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Database ,Crystal Reports, anb Vb.Net 2005

    Your welcome. If this resovles this issued please mark the thread as RESOLVED using the thread tools in the menu.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width