Question : Why I need crystal report file path?

Hi,

I asking why I need reportdoc.Load("C:\Users\fsze88\Desktop\kennam\vb.NET\kennamCustomers.rpt")
on vb.net code?
some to way simplify this?

Thank you!
Francis SZE
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
Private Sub customerReportForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim reportdoc As New ReportDocument
        Dim logoninfo As New TableLogOnInfo

        reportdoc.Load("C:\Users\fsze88\Desktop\kennam\vb.NET\kennamCustomers.rpt")


        Dim oradb As String = "Data Source=kennam;User Id=kennam;Password=kennam007;" ' VB.NET
        Dim conn As New OracleConnection(oradb)
        conn.Open()

        Dim sql As String = "select * from customers " ' VB.NET
        Dim cmd As New OracleCommand(sql, conn)
        cmd.CommandType = CommandType.Text
        Dim dr As OracleDataReader = cmd.ExecuteReader()
        Dim ds As New DataSet()
        Dim adapter As New OracleDataAdapter(sql, conn)
        adapter.Fill(ds)

        '        For Each table In reportdoc.Database.Tables
        ' logoninfo = Table.LogOnInfo
        'logoninfo.ConnectionInfo.ServerName = "localhost"
        'logoninfo.ConnectionInfo.DatabaseName = "kennam"
        'logoninfo.ConnectionInfo.UserID = "kennam"
        'logoninfo.ConnectionInfo.Password = "kennam007"
        'Table.ApplyLogOnInfo(logoninfo)
        'Next table

        CrystalReportViewer1.ShowRefreshButton = False
        CrystalReportViewer1.ReportSource = reportdoc
    End Sub
Attachments:

Answer : Why I need crystal report file path?

You can replace the Application path as below, this will take the path based on the installation.

reportdoc.Load(App_Path() & "kennamCustomers.rpt")


********************************
    Public Function App_Path() As String
\bin\Debug"
        Return System.AppDomain.CurrentDomain.BaseDirectory()
    End Function


You can also use the System.Reflection namespace to get the properties of your Assembly. Try this VB.NET code:

    Dim aPath As String
    Dim aName As String

    aName = _
      System.Reflection.Assembly.GetExecutingAssembly. _
      GetModules()(0).FullyQualifiedName    

    aPath = System.IO.Path.GetDirectoryName(aName)
 

Random Solutions  
 
programming4us programming4us