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.
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.