Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 859
  • Last Modified:

Creating a crystal report from datasets

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 btnprint.click
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?

  • 6
  • 4
1 Solution
wardnAuthor Commented:
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.

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"


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

wardnAuthor Commented:
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.
wardnAuthor Commented:
If I can only control the table via giving it parameters. Is there a way using the guid as the paramter

crrpt.recordselectionformula = "{tbliradmin.id} = 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 "tbliradmin.id" is equal to. I still can't figure out how to use that
please help
wardnAuthor Commented:
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
wardnAuthor Commented:
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-.......'
Try it this way
crrpt.recordselectionformula = "{tbliradmin.id} = " & cstr(intGUID)

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

wardnAuthor Commented:
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.

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now