Creating a crystal report from datasets

Posted on 2003-12-06
Last Modified: 2013-12-25
I have a visal baisc .net application that is used by security personnel. I want to create a crystal report that uses the datasets withen the application for data. I can't get it to load the data. everytime I select to load the crystalreportpreview I get a message box for logging into the server. I would enter all the correct data, but I would get a logon error.

I then found out there is a way using the ole db interface in crystal report to link to the server. I then could connect to the server and display data, but I cannot limit the report to a specific report that needed to be printed (i.e. print the spicific (form) report that is in the database (not the crystal), but I can't figure out how to just filter what info I need). I would like to have the crystal report data come from the datasets. Is there a way to do this with out it having to connect to the server? In other words.

form1.btnprint (byval.....).handle
dim printform as new frprint()

frprint has a crystal report viewer that its reportsource is crystalreport1.rpt
the crystalreport1.rpt would get its data from the datasets that are in the project. But I want it to do this with out asking for any type of connection string. I have the datasets filled prior to the form opening and I want the crystalreport to use these dataset for data. All the fields in the crystal report would come from the datasets.

I did notice though that when you add the dataset to the crystal report it would link to the server table that the dataset uses. I just want the data to come directly form the dataset not the server. The dataset would already have all the data from the server that it would need. Is there a way to do this? or is there a better way of doing this?

Question by:wardn
  • 6
  • 4
LVL 100

Expert Comment

ID: 9887995

Author Comment

ID: 9888061
I have already tried that and it works that is what I descriped above. It uses an ole db (ado) connection to the server. I said above that I can connect to the server database just like they use in this example. The program is not a web based type program yet. I am just creating an application that uses windows forms. I understand that I can uses tables from the database on the SQL, but I would like to use the dataset instead. That way everything is already loaded for data and the only thing it has to do is show the report. But if using the ole DB is the only way to get the data into the crystal report then is there a way to select a SQL statement for these tables being used in the crystal report using a parrameter that is given from the windowsform (i.e. "intString")? If so how. The reason I say this is because I noticed if you open the crystal report in visual basic .net, open the table, and right mouse click on a field you can select "select expert...." you can give it parramters. but if you can do this where is the stored procedure for this, because I can't find it.
 There has to be a way to use a disconnected connection and have the crystal report come off of the dataset and the data it has in it with out being connected to the Server. the reason I say this is because it would not be an availble option if it wasn't, but I don't know how to just tell the crystal report that it does not need to connect to the SQL server. Also think there should be a way is because in the windows form once the dataset is filled all the data is in the dataset that will be used.

LVL 100

Expert Comment

ID: 9888392
That is what an ado recordset is.  Are you using ado recordsets or some other dataset?

I build all my reports based on views from the database then pass the where clause from VB

In VB using the RDC it is something like

crRpt.RecordSelectionFormula = "{view.intString} = 5"

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Author Comment

ID: 9895483
I am currently using a ADO Recordset, but I would like it to just use the datasets that are withen the application. I was wondering what is the purpose of the .vb side of the crystal report. I noticed that I can add SQL connections, SQLDataAdapters(that can used stored procedures), and datasets. Why can't I use the datasets that are withen the application which are filled by the SQL server (data adapters). I noticed the only way I can get data to show is to use tables under the OLE DB (ADO) which uses the microsoft jet engine for SQL Servers.
I don't understand how to use the formula section of crystal report.
I noticed that you have crRPT.recordselectionformula = "[view.intString} = 5"
How do I do this with a GUID field?

Why is it that if you use datasets it askes for a server connection when the datasets are right there within the application. I noticed that the only way you can add the datasets is through the ADO.NET Datasets. under project Data folder.

Author Comment

ID: 9896304
If I can only control the table via giving it parameters. Is there a way using the guid as the paramter

crrpt.recordselectionformula = "{} = intGUID"
intGuid is a guid
and tbliradmin.ID is a guid field
the reason for this is because when I add the next table to the report it will go by what ever "" is equal to. I still can't figure out how to use that
please help

Author Comment

ID: 9896434
I forgot to mention that intGUID is a global variable that is given when you open the document prior to print document. the intGUID is declared in the GLOBAL.vb

Author Comment

ID: 9896840
I found a way to get only one record to show, but I don't know how to make it dynamic.
what I did was right mouse click on the tblIRadmin.ID and then clicked "Select Expert..." What I did was select the ID field and told it to be = to a number already loaded. So now I got it to load the only record, But I don't know how to control this formula that it makes it dynamic to the "intGUID.
What I did find out using the procedure above was that if I make intGUID.ToString it helped converting it into a string, but passing it on I am still having problems. The ID field is not shown in the report. Just one of the items available on the side in the fields box.
Is there a way to pass the intGUID.ToString paramater into this field.
So now my right now my SQL statement is
Select "tblIRadmin.ReportNumber" from "tblIRAdmin" where "TblIRadmin.ID = 123124-.......'
LVL 100

Expert Comment

ID: 9901872
Try it this way
crrpt.recordselectionformula = "{} = " & cstr(intGUID)

I am not sure what you mean by datasets in VB?  Do you mean the datacontrols?


Author Comment

ID: 9902955
When I try that I get an error:
"Object reference not set to an instance of an object"
It did not work still
I have even tried:
dim selectformula as string
dim selectformula1 as string = intGUID.ToString
selectformula = "{tblIRadmin.ID = " & selectformula1
crrpt.recordselectionformula = selectformula
this didn't even work.
It is not passing the info to the crystalreport. I don't know why I have followed your instructions and the instructions that are in the help section of VB.

What I mean by datasets in VB:
when you create a data adapter between the server and the application you can generate a dataset that the data will be placed into from the data adapter. the dataset is used to hold the data temporarly and the data adapter used it to store data from the server and is used to update data to the server. It is like a copy of the table in the server placed withen the application so that you do not tie up the connection spool between the application and the server.

LVL 100

Accepted Solution

mlmcc earned 150 total points
ID: 9924458
I don't believe you can use those unless it is an ADO recordset.

What is the full code you are using to call the report?


Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now