Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Wasn't sure where else to post this, so I'll try here. :)

 

I have found no way to create a report so that the database it uses contains no path information. I want the report to look for the database in the same folder as the report without a hard-coded path. This is using version 9 of Crystal Reports with VB.NET.

Here's what I'm up to.
  • 2 weeks later...
Posted
I haven't used Crystal Reports with .NET yet, but Crytal Reports 7 has a Database -> Set Location... menu option. Click that and the tables in the report show up. The path is defaulted to current directory and if you move the report is tries to find the database in the path where the report is created. If you click the button Same as Report, the path is removed and your report will run as long as it is in the same directory as the database.
rustyd
  • 5 months later...
  • 5 years later...
Posted

Hi, all

 

It took me a lot of hours of surfing the web trying to find a solution to this exact problem, and after giving up searching for an answer, I decided to try my own way... and after a couple of hours playing around with Crystal Reports (mine is for Visual Studio 2008, I think is CR 9...) I found a solution.

 

All we need to do is use a Datatable to fill in the report.

 

Here´s how I did it:

 

I first created a Dataset, added a new Datatable (myDataTable) and added a few columns to it (Col1, Col2).

 

Then I created the report (myreport), and set the source to be the Dataset I created before, that filled in the fields in the report with the fields I added to my Datatable.

 

Then I went to the actual code that loads my report, in my case it's the Load event on the form containing the Crystal Reports Viewer (myCRViewer).

 

Here's the code:

 

Dim rep As New myreport

Dim dt As New myDataTable

 

Dim strQuery As String = "SELECT Col1, Col2 FROM myDB WHERE Col2 > 0"

 

Dim con As New OdbcConnection("Dsn=dBASE Files;defaultdir=C:\DB;driverid=277;fil=dBASE IV;maxbuffersize=2048;pagetimeout=5")

 

dt.Columns.Clear()

dt.Rows.Clear()

dt.Columns.Add("Col1")

dt.Columns.Add("Col2")

 

Dim objCommand As OdbcCommand = New OdbcCommand(strQuery, con)

 

Dim objAdapter = New OdbcDataAdapter(objCommand)

 

objAdapter.SelectCommand = objCommand

objAdapter.Fill(dt)

rep.SetDataSource(dt)

myCRViewer.ReportSource = rep

 

We just need to build the path into the connection string, using either a textbox, a string variable or even a user selection instead of "C:\myDB" and we're ready to work!

 

This actually solved two of my problems, it was of course setting the location for my DBF database and also the use of SQL queries which I wasn't able to use, and had to use the RecordSelectionFormula...

 

Hope this helps you guys get back in track!

 

By the way, after making sure it worked, I even deleted the dataset and it still works. If you have any problems getting this code to work, just let me know, because I edited a little bit first to post it here...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...