Connecting to DB

Ok heres the run down guys. This is the final step in the program I have created so thanks to all that have helped me thus far.

1. Report was created in Crystal Reports XI, database connected fine through it yada yada yada all works fine.

2. Combined the Report into Visual Basic .net application (windows application not web) and have got everything to show up via CrystalReportViewer.

3. I have an ini file that has the path to the database in which the report should pull its data from (an access db) so I have created some coding (with the help of the vb people in the vb forum) code to read that ini file, pull the line that has the path to database on the server.

Now here is my question, how would I do it in VB to send the path of the database to the report, connect and display it in the report viewer.

So pretty much take the string in which I have placed the path and redirect the db the report connects to that path I have in the string.

Here is a code I have tried working with but it doesnt work:

Dim crTable As Table
Dim reportPath As New ReportDocument
For Each crTable In reportPath.Database.Tables
crTable.Location = Application.StartupPath & Path2(1)
Next crTable
myCrystalReportViewer.ReportSource = (Application.StartupPath & "sampleReport3.rpt")

Oh and im doing all that in the same place I am finding the path thats why I didnt declare Path2 again.

Thanks



Answer this question

Connecting to DB

  • cliffhanger9

    hey guys,

    I have successfully figured it out! thanks for all the help.

    Hope to see you guys soon ;)


  • greenmind

    hey thanks, fixed it but another problem. I get the following error:

    An unhandled exception of type 'CrystalDecisions.CrystalReports.Engine.InvalidArgumentException' occurred in crystaldecisions.crystalreports.engine.dll

    Additional information: Error in File C:\Documents and Settings\mau\My Documents\Visual Studio Projects\Report\bin\sampleReport3.rpt:
    Invalid table number.

    The updated connection code:

    'Loads Report and Connects to Database
    reportPath.Load(Application.StartupPath & ".\sampleReport3.rpt")
    For Each crTable In reportPath.Database.Tables
    crTable.Location = Application.StartupPath & Path2(1)
    Next crTable
    myCrystalReportViewer.ReportSource = Application.StartupPath & ".\sampleReport3.rpt"

    thanks






  • cfendya

    I dont know too much about Crystal Reports but just looking at your code here, you have invalid paths specified. Application.StartupPath does not include the trailing \. So your path looks like the following: "C:\MyProjectPathsampleReport3.rpt". Maybe that will help, like I said, I am not a Crystal Reports guru.

  • huahsin68

    In this line of code:

    crTable.Location = Application.StartupPath & Path2(1)

    What is Path2(1) set to Did you include the \ in that path also



  • Duie

    Path2(1) is an array with a string of the database path.

    For more info --> http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=249999&SiteID=1

    I believe you helped me there aswell.


  • Connecting to DB