Sample Application: FFAssist using Crystal .NET for Visual Studio 2005 - Part 3
page 3 of 5
by Eric Landes
Feedback
Average Rating: 
Views (Total / Last 10 Days): 25048/ 111

Creating the Data Object

I wanted to see if Visual Studio can create Business Objects quickly.  I did not look thoroughly through the Visual Team System features, because I suspect there are some good tools there for accomplishing this.  However, I did find a way to automatically generate an object based on a DataSet that could serve as my business object.

To do this, in my Visual Studio Solution, I added a Windows Project to my solution, by right-clicking on the solution, and selecting Add New.  I then selected the Windows Application project template. 

Figure 2:

 

First, open the form Form1 that was automatically created.  Then, from the toolbox, add a BindingSource.  In the properties of the BindingSource, under Application Settings, open the DataSource Dialogue box, and click on Add Project Data Source. 

Follow the Data Source Configuration Wizard by selecting Database as your Data Source type.  In the Data Connection dialogue, create a new connection to the FFAssistant database on your local server.  Next, save the connection string to the web.config file.  We will use this string later in the web application.

In the next dialogue box, select the four tables Players, Positions, Stats, and Teams.  Name the DataSet FFAssistantDataset.  Now the DataSet object has been created.

Unfortunately, this object has been created in the wrong project.  To overcome this hurdle, in my solution I added the files FFAssistantDataSet.xsd and FFAssistantDataSet.Designer.cs to the FFBusObjects project using "Add Existing Files".  To accomplish this in the FFBusObjects project, right-click on the project, and then select "Add Existing".

This method of creating the object also does not have a connection property, but has an automated method of retrieving the connection string.  So we need to add a public property to the class to be able to set the connection string in code.

To add that flexibility to this class, I added the following line to the top of the following classes: PlayersTableAdapter, PositionsTableAdapter, StatsTableAdapter, and TeamsTableAdapter:

Listing 2: Connection String Property

Public_String MainConnection = "";

After inserting the above string at the top of each TableaAapter class, we also need to change the connection initiation to utilize this property.  To do this, we need to change the InitConnection method of each of these classes.  Do this with the following code:

Listing 3: Code change in InitConnection

private void InitConnection()
{
    this.m_connection = new System.Data.SqlClient.SqlConnection();
    this.m_connection.ConnectionString = MainConnection;
}

Now, we can set the connection in code with this business object, and we created the object using a new method in Visual Studio 2005.  While we won't use the methods, Delete, Insert, and Update methods are automatically created using this method.  We'll use the Fill method of the adapter to put all the data in the report.  The next thing we're going to do is the data binding to the report.


View Entire Article

User Comments

Title: Crystal Report for Visual Studio 2005   
Name: waiche
Date: 2006-02-09 9:31:58 AM
Comment:
Help me ! I used Crystal Report in ASP.NET pages with VS2005. When I used ASP.NET Development Server to test, it is ok. But I used IIS Server to test, it throw an error. (Error: Report load fail). Report can't display
(my email: waicheqn@yahoo.com.vn)
Title: Problems about SQLEXPRESS db version   
Name: Sabry
Date: 2005-11-08 10:26:59 AM
Comment:
\S
Title: re: Abdullah Alshuaili   
Name: Daniel Nico
Date: 2005-11-08 7:27:47 AM
Comment:
How do you set a relative path to a datasource location in Crystal Reports? Please let me know how you did this.
Title: very nice   
Name: Abdullah Alshuaili
Date: 2005-09-07 5:22:26 PM
Comment:
Thank u very much a useful page, it was better if u set relative path instead of absloute in case of crystal reports in vb .net !!!!

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2020 ASPAlliance.com  |  Page Processed at 2020-08-03 11:03:01 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search