Results 1 to 10 of 10

Thread: crystal report path

  1. #1

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    crystal report path

    hi guys...
    i am new to vb.net 2003 and am using crystal reports to print my reports..
    i have a accounting package...where the client has more than 1 company...now the prob is i have design the report using 1 company...i would like to know how i can run the same report for the 2nd or 3rd company...
    can anyone pls. guide me ...
    thankx in advance....

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: crystal report path

    Change the DataSource according to the selected company

  3. #3

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: crystal report path

    hi...i am stuck at the report data source part...

    i have tried
    Code:
      myPath = txtPath.Text
            xPrd_Code = txtPrd_Code.Text
            MyConConnection = objConn.OpenCompany(myPath)
            MyConConnection.Open()
    and then giving
    Code:
       Dim myreport As New rptPurchaseSumReport
                                    myreport.SetDataSource(MyConConnection)
    and even have tried
    Code:
    myreport.SetDataSource(txtPath.Text)
    i have 2 companies...
    1 table is company1 and 2nd is company2
    i have created the report using company2 but even if i do the above both ways its showing me the data of company2 only...where as i am selecting company1 and then running the report....
    the txtpath.text is correct as the data is showing of company1

    would b greatful for a early reply...thankx a lot...
    eagerly waiting for the reply....
    thankx

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: crystal report path


  5. #5

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: crystal report path

    hi guys...thankx for the help ...i have done the following too...but still i cant set the path for the report...

    Code:
     Dim myreport As New rptBillPrinting
    
                    Dim con As New OleDbConnection
                    Dim da As New OleDbDataAdapter
                    Dim cmd As New OleDbCommand
    
                    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & txtPath.Text
                    cmd.Connection = con
                    da.SelectCommand = cmd
                    da.MissingSchemaAction = MissingSchemaAction.AddWithKey
    
                    con.Open()
                    cmd.CommandText = "Select * from Sale WHERE Prd_Code = '" & txtPrd_Code.Text & "' AND BillNo = '" & txtBillNo.Text & "'"
                    da.Fill(ds, "Sale")
                    cmd.CommandText = "Select * from SaleDet WHERE Prd_Code = '" & txtPrd_Code.Text & "' AND BillNo = '" & txtBillNo.Text & "'"
                    da.Fill(ds, "SaleDet")
                    cmd.CommandText = "Select * from LedgerMaster"
                    da.Fill(ds, "LedgerMaster")
                    cmd.CommandText = "Select * from ItemMaster Where ItemType = 'F'"
                    da.Fill(ds, "ItemMaster")
    
                    myreport.SetParameterValue("CompanyName", txtCoName.Text)
                    myreport.SetParameterValue("CoAdd1", txtCoAdd1.Text)
                    myreport.SetParameterValue("CoAdd2", txtCoAdd2.Text)
                    myreport.SetParameterValue("CoAdd3", txtCoAdd3.Text)
                    myreport.SetParameterValue("Rupees", txtRupees.Text)
                    myreport.SetDataSource(ds)
    
                    crForm.CrystalReportViewer2.ReportSource = myreport
    
                    Fltr = "{Sale.Prd_Code} = '" & txtPrd_Code.Text & "'"
                    Fltr = Fltr & " AND {Sale.BillNo} = '" & txtBillNo.Text & "'"
    
                    crForm.CrystalReportViewer2.SelectionFormula = (Fltr)
                    crForm.Show()
    but even then its taking from the path where i have created the report
    the report does not give any error but still takes it from the same mdb file that i have used when i created the report

    pls. pls. pls. help....
    thankx

  6. #6
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: crystal report path

    Hope this help You :

    Code:
    Function ApplyLogon(ByVal cr As ReportDocument, ByVal ci As ConnectionInfo) As Boolean  
     
    Dim li  As TableLogOnInfo  
    Dim tbl As Table  
     
    ' for each table apply connection info   
    For Each tbl In cr.Database.Tables  
        li = tbl.LogOnInfo  
        li.ConnectionInfo = ci  
        tbl.ApplyLogOnInfo(li)  
     
        ' check if  logon was successful  
        ' if  TestConnectivity returns false,  
        ' check logon credentials  
        If  (tbl.TestConnectivity()) Then  
            'drop fully qualified table location  
            If  (tbl.Location.IndexOf(".") > 0) Then  
                tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)   
            Else  
                tbl.Location = tbl.Location  
            End If   
        Else  
            Return False  
        End If   
        Return True  
    Next  
    End Function  
     
    
    'The Logon method iterates through all tables  
    Function Logon(ByVal cr As ReportDocument, ByVal server As String, ByVal db As String, ByVal id As String, ByVal pass As String) As Boolean  
     
    Dim ci     As New ConnectionInfo()  
    Dim subObj As SubreportObject  
    Dim obj    As ReportObject  
     
    ci.ServerName = server  
    ci.DatabaseName = db  
    ci.UserID = id  
    ci.Password = pass  
     
    If  Not (ApplyLogon(cr, ci)) Then  
        Return False  
    End If   
     
    
    For Each obj In cr.ReportDefinition.ReportObjects  
        If  (obj.Kind = ReportObjectKind.SubreportObject) Then  
            subObj = CType(obj, SubreportObject)  
            If Not (ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci)) Then  
    	    Return False  
            End If   
        End If   
    Next  
    Return True  
    End Function

  7. #7

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: crystal report path

    thankx jggtz for ur reply...i would surely try it as soon as i reach my place...but one more thing...i dont have a user name and password for the database...and the pc is a standalone one....so how do i do it...
    sorry for the trouble....thankx a lot all u guys for being a great help....i will get back with the results by the day end.thanx

  8. #8

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: crystal report path

    jggtz sorry for replying sooo late...but first of all i took a lot of time to understand what and how it is being done as am very new to vb.net 2003 and secondly i have been trying and trying to get it working ....
    i know theres nothing wrong with the code but everythings wrong with me lol.
    i am using vb.net 2003 and its standalone
    i have called the function as below
    Code:
     Logon(mRpt, "kuldev", txtPath.Text, "Admin", "")
    i even tried giving the server name as "" as i am not using any server....can u pls. guide me how i can call it...

    someone pls. help me out plssssss...
    thankx

  9. #9
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: crystal report path

    Other way :
    Code:
    'To pass logon information to a Crystal Report at runtime, use the following code sample:
    
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    
    
    Dim crtableLogoninfos As New TableLogOnInfos()
    Dim crtableLogoninfo As New TableLogOnInfo()
    Dim crConnectionInfo As New ConnectionInfo()
    Dim CrTables As Tables
    Dim CrTable As Table
    Dim TableCounter
    
    'If you are using a Strongly Typed report (Imported in
    'your project) named CrystalReport1.rpt use the
    'following:
    
    Dim crReportDocument As New CrystalReport1()
    
    'If you are using a Non-Typed report, and
    'loading a report outside of the project, use the
    'following:
    
    Dim crReportDocument As New ReportDocument()
    
    crReportDocument.Load("c:\myReports\myReport.rpt")
    
    'Set the ConnectionInfo properties for logging on to
    'the Database
    
    'If you are using ODBC, this should be the
    'DSN name NOT the physical server name. If
    'you are NOT using ODBC, this should be the
    'physical server name
    
    With crConnectionInfo
    .ServerName = "DSN or Server Name"
    
    'If you are connecting to Oracle there is no
    'DatabaseName. Use an empty string.
    'For example, .DatabaseName = ""
    
    .DatabaseName = "DatabaseName"
    .UserID = "Your User ID"
    .Password = "Your Password"
    End With
    
    'This code works for both user tables and stored
    'procedures. Set the CrTables to the Tables collection
    'of the report
    
    CrTables = crReportDocument.Database.Tables
    
    'Loop through each table in the report and apply the
    'LogonInfo information
    
    For Each CrTable in CrTables
    CrTableLogonInfo = CrTable.LogonInfo
    CrTableLogonInfo.ConnectionInfo =
    crConnectionInfo
    CrTable.ApplyLogOnInfo(crtableLogoninfo)
    
    'If your DatabaseName is changing at runtime, specify
    'the table location.
    'For example, when you are reporting off of a
    'Northwind database on SQL server you
    'should have the following line of code:
    
    crTable.Location = "Northwind.dbo." &
    crTable.Location.Substring(crTable.Location.LastIndexOf(
    ".") + 1)
    Next
    
    'Set the viewer to the report object to be previewed.
    
    CrystalReportViewer1.ReportSource = crReportDocument
    JG

    Also it may help that you visit --->
    https://boc.sdn.sap.com/taxonomy/term/3

    If you are changing database at runtime, it is
    important that you specify the table location
    after you apply logon information (this is a case
    sensitive property). You can either specify the table name
    only or the fully qualified table name such as

    crTable.location = "databaseName.dbo.tablename"

    • Refer to knowledge base article c2010275 if you
    wish to change database logon information in the
    main and subreport.

    • If you are reporting off an Access database, then
    specify either the 'ServerName' or 'DatabaseName'
    to the 'ConnectionInfo' Object depending on
    how you are connecting to Access.

    For example, if you are connecting to Access
    through ODBC, then set the 'DatabaseName' for the
    'ConnectionInfo' object as follows:

    With crConnectionInfo
    .DatabaseName = "C:\mydatabase\mydata.mdb"
    End With

    If you are connecting to Access through OLE DB,
    then set set the 'ServerName':

    With crConnectionInfo
    .ServerName = "C:\mydatabase\mydata.mdb"
    End With

    It is not possible to report of a secured Access
    database using a native connection. See knowledge
    base article C2010460 for more information.

    • If you are using more than one database with
    different usernames and passwords, use a loop to
    pass in the different values.

  10. #10

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: crystal report path

    thankx a lot i got it working.....thankx for the great help.....
    can i one more question b answered here ....or do i have to post a new thread for it....
    is there any way to change the font of the report programatically
    say i develop a prog. where the user selects the font he / she wants and then the same font should b applied to the report too...

    thankx a lot for ur help...

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