Go Search
Skip navigation links
Home
E-Services
Technology Center
Consultancy
Support Services
Enterprise Strategy Consultancy
Other Blogs
There are no items in this list.
The Best Practice of creating a solution in Visual Studio 2008

This article provides a guidance on how to create a solution using Microsoft Visual Studio 2008. Many developers start working with simple solution and when it gets bigger, they complain about complexity of searching for specific files and end up with disorganized environment. The more effort trying to keep a solution well structured, the easier a developer’s life is going to be.

It is better to divide a solution into folders and sub-folders, in which common files go in one place under each application a solution can have. That makes it easier to maintain manageability of a solution.  Following the steps that this article provides gives a good idea of how to create a neat solution easily. 

  

Creating well structured solution

 

The below is step by step instruction of how better you can create a solution with multiple files.

 

1.    Open Visual Studio

2.    Go to File > New Project

Figure 1

3.    Select the language you are using, (VB / C#) and then select a "Blank Solution", give it a name (e.g. "My Solution") and save it in any location in your machine. Figure 1.

Figure 2

4.    Go to the Solution Explorer in your new solution you have just created and right click your solution and choose "Add", then Select "New Solution Folder" and give it a name (e.g. "Project 1"). Figure 2.

5.    Go to the Solution Explorer and right click the folder you just created and choose "Add", you can add a new project/website to your solution or select an existing one and then click ok. Your new project/website is now added inside that folder with all its default files, check figure 3.

Figure 3

It is recommended to add a solution folder for each Application you add to a single solution if you are going to have multiple applications in it. Also, you can add applications with different types to the same solution. (E.g. Figure 4)

Figure 4

6.    Now after you have added your first application to the Solution Folder, you can create other sub folders to manage the application`s files based on their types (e.g. "Images" folder to put all images related to that application in that folder, so it will be more organized, Check Figure 5).

Figure 5

Figure 6

ASP.Net folders can be added as subfolders under the solution folder (e.g. "Themes" folder to store .CSS files, check Figure 6).

The benefit of having the well structured folders and files in a solution is to have not just a logical order inside the solution but also to have a well organized order of folders and files of a solution with multiple applications physical as in the following figure (Figure 7).

Figure 7

 

How to access database using ActiveX Data Object

In many cases you need to create a CD web application that reads from a database but you cannot use asp.net which requires to be hosted first on IIS. And other cases where you need to access database and you can’t use data access libraries. Then you can use ActiveX Data Objects.

Microsoft introduced ActiveX Data Objects (ADO)  to the world during the winter of 1996. ADO is a set of Component Object Model (COM) objects for accessing data sources.

To create web application that accesses  database  without using asp.net, you can create a script (JavaScript, Jscript, …) which accesses the database using ActiveX controls.

Suppose you need to open a database and read from its tables to display the data on a web form. You should follow these steps:

1-     Make a script in HTML page to write the code to access database using ActiveX controls. For example you can write it in  vbscript or JavaScript.

2-     Inside the script create a method  to declare and initialize activeX object

3-     Create ActiveXObject  for a connection

4-     Define the connection string and open the connection object with this connection string

5-     Create ActiveXObject   for a recordset

6-     Define a  query  and open the recordset

7-     Read or write in the recordset

8-     Close the recordset

9-     Close the connection

These steps should be included in a function inside the script like this:

<script language = "javascript" type = "text/javascript">

function getEmployess(){

   var cn = new ActiveXObject("ADODB.Connection");

   ………

   ………

}

</script>

 

let's illustrate these steps by the following example:

Suppose there is an access database have information about company. One table is Employee table that we want to read from.  Each employee has a unique id and other information like name , salary and date of birth.

To do this we should go through these steps :

1-     Create an ActiveX object for a connection:

Any ActiveXObject is created like this:

 

newObj = new ActiveXObject(servername.typename[, location])

Arguments:

newObj : Required. The variable name to which the ActiveXObject is assigned.

servername : Required. The name of the application providing the object.

typename : Required. The type or class of the object to create.

 

location : Optional. The name of the network server where the object is to be created.

 

In our example:

// create a connection

var cn = new ActiveXObject("ADODB.Connection");

 

2-     Declare connection string

Set the connection string to the data source. You should specify the data source and any other parameters you need. Make sure to use the correct provider in the connection string.

 

//create a connection string  

var strConn = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:\\myDataBase.accdb";

 

3-     Open the connection object

To open the connection object previously created you should use the connection string as a parameter.

 

      // open the connection

      cn.Open(strConn);

 

4-      Create an ActiveX object for a recordset

As in step 1, create a recordset.

 

// create a recordset

      var rs = new ActiveXObject("ADODB.Recordset");

              

5-      Populate the recordset (Define query and open the recordset)

Write your SQL query needed to access the database and then use the query string and the connction object as parameters to open the recordset.

 

var SQL = "select Employee_Name, Employee_Salary, Employee_Birthdate from Employee";

      rs.Open(SQL, cn);

 

6-      Manipulate the recordset

You can read or write to the record set. There are multiple methods and properties you can use recordset like:

·         "MoveFirst": Method to move to the first record.

·         "MoveLast": Method to move to the last record.

·         "MoveNext": Method to move to the next record.

·         "MovePrevious": Method to move to the previous record.

·         "BOF": Property to return true if the current record pointer is before the first record.

·         "EOF": Property to return true if the current record pointer is after the last record.

·         "Fields": Property to return a collection representing all the fields of the current record.

You can also read the fields in the current record in the record set by specifying the index of the field in the recordset object. For example: rs(0) returns the value of first field in the current record in the recordset rs.

 

 

7-      Close the recordset

// close the recordset object

rs.Close();

 

8-      Close the connection

// close the recordset object

cn.Close();

 Blogs

The Best Practice of creating a solution in Visual Studio 2008Use SHIFT+ENTER to open the menu (new window).
Rasha Al Abdali
How to access database using ActiveX Data ObjectUse SHIFT+ENTER to open the menu (new window).
Ameera Al Busaidi
Next Generation of Development WCF and WF, code-name "Dublin"Use SHIFT+ENTER to open the menu (new window).
Mohamed Al Zadjali
Blackcomb, Vienna the baby takes its first breath in ISCUse SHIFT+ENTER to open the menu (new window).
Portal Administrator

 ‭(Hidden)‬ Admin Links

 
All Rights 2010 © Reserved for Innovation & Support Center Tel:24166777 E-Mail: Support@isc.gov.om Contact Us