Sunday, April 8, 2012

Sorting of Array without built in function


  • We are using bubble sort algorithm for the Sorting of ARRAY.
 static int[] ArraySort(int[] input)
        {
            int count = input.Length;
            int temp = 0;
            do
            {
                int newcount = 0;
                for (var i = 1; i < count; i++)
                {
                    if (input[i] < input[i - 1])
                    {
                        temp = input[i];
                        input[i] = input[i-1];
                        input[i-1] = temp;

                        newcount = i;
                    }
                }
                count = newcount;
            } while (count > 0);

            return input;

        }

Friday, April 6, 2012

String Reverse without BuiltIn function.....

  • Here we are extensively using string builder class which is mutable, ie editable. In other words it does not create a new copy during the operations as opposed to string class.
  • It is a best practice to try with static methods and classes which are not instance specific
  • We remember string is array of chars....
 static string stringreverse(string input)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = input.Length-1; i >= 0; i--)
            {
                sb.Append(input[i]);

            }

            return sb.ToString();
        }

Tuesday, April 3, 2012

GC.Collect() and finalize

System.GC.Collect() forces garbage collector to run for managed code.


.NET Garbage collector does almost all clean up activity for your objects. But unmanaged
resources (ex: - Windows API created objects, File, Database connection objects, COM
objects etc) is outside the scope of .NET framework we have to explicitly clean our
resources. For these types of objects .NET framework provides Object.Finalize method
which can be overridden and clean up code for unmanaged resources

Is Global.ASAX file is a must for asp.net applications?

Yes. At run time, upon the arrival of the first request, Global.asax is parsed and compiled into a dynamically generated and used to declare data that is available across different application requests or across different browser sessions.

Monday, April 2, 2012

WebService and WCF difference

Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type. 

Second web services are not flexible. However, WCF Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends. 

We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc 

For more details, read http://msdn.microsoft.com/en-us/library/aa738737.aspx

Difference between ADO and ADO.NET


In-memory Representations of Data

In ADO, the in-memory representation of data is the recordset. In ADO.NET, it is the dataset. There are important differences between them.

Number of Tables

A recordset looks like a single table. If a recordset is to contain data from multiple database tables, it must use a JOIN query, which assembles the data from the various database tables into a single result table.
In contrast, a dataset is a collection of one or more tables. The tables within a dataset are called data tables; specifically, they are DataTable objects. If a dataset contains data from multiple database tables, it will typically contain multiple DataTable objects. That is, eachDataTable object typically corresponds to a single database table or view. In this way, a dataset can mimic the structure of the underlying database.
A dataset usually also contains relationships. A relationship within a dataset is analogous to a foreign-key relationship in a database —that is, it associates rows of the tables with each other. For example, if a dataset contains a table about investors and another table about each investor's stock purchases, it could also contain a relationship connecting each row of the investor table with the corresponding rows of the purchase table.
Because the dataset can hold multiple, separate tables and maintain information about relationships between them, it can hold much richer data structures than a recordset, including self-relating tables and tables with many-to-many relationships.

Data Navigation and Cursors

In ADO you scan sequentially through the rows of the recordset using the ADO MoveNext method. In ADO.NET, rows are represented as collections, so you can loop through a table as you would through any collection, or access particular rows via ordinal or primary key index. DataRelation objects maintain information about master and detail records and provide a method that allows you to get records related to the one you are working with. For example, starting from the row of the Investor table for "Nate Sun," you can navigate to the set of rows of the Purchase table describing his purchases.
cursor is a database element that controls record navigation, the ability to update data, and the visibility of changes made to the database by other users. ADO.NET does not have an inherent cursor object, but instead includes data classes that provide the functionality of a traditional cursor. For example, the functionality of a forward-only, read-only cursor is available in the ADO.NET DataReader object. For more information about cursor functionality

Minimized Open Connections

In ADO.NET you open connections only long enough to perform a database operation, such as a Select or Update. You can read rows into a dataset and then work with them without staying connected to the data source. In ADO the recordset can provide disconnected access, but ADO is designed primarily for connected access.
There is one significant difference between disconnected processing in ADO and ADO.NET. In ADO you communicate with the database by making calls to an OLE DB provider. In ADO.NET you communicate with the database through a data adapter (an OleDbDataAdapter,SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object), which makes calls to an OLE DB provider or the APIs provided by the underlying data source. The important difference is that in ADO.NET the data adapter allows you to control how the changes to the dataset are transmitted to the database — by optimizing for performance, performing data validation checks, or adding any other extra processing.
Note   Data adapters, data connections, data commands, and data readers are the components that make up a .NET Framework data provider. Microsoft and third-party providers can make available other .NET Framework data providers that can be integrated into Visual Studio. For information on the different .NET Data providers, see .NET Data Providers.

Sharing Data Between Applications

Transmitting an ADO.NET dataset between applications is much easier than transmitting an ADO disconnected recordset. To transmit an ADO disconnected recordset from one component to another, you use COM marshalling. To transmit data in ADO.NET, you use a dataset, which can transmit an XML stream.
The transmission of XML files offers the following advantages over COM marshalling:

Richer data types

COM marshalling provides a limited set of data types — those defined by the COM standard. Because the transmission of datasets in ADO.NET is based on an XML format, there is no restriction on data types. Thus, the components sharing the dataset can use whatever rich set of data types they would ordinarily use.

Performance

Transmitting a large ADO recordset or a large ADO.NET dataset can consume network resources; as the amount of data grows, the stress placed on the network also rises. Both ADO and ADO.NET let you minimize which data is transmitted. But ADO.NET offers another performance advantage, in that ADO.NET does not require data-type conversions. ADO, which requires COM marshalling to transmit records sets among components, does require that ADO data types be converted to COM data types.

Penetrating Firewalls

A firewall can interfere with two components trying to transmit disconnected ADO recordsets. Remember, firewalls are typically configured to allow HTML text to pass, but to prevent system-level requests (such as COM marshalling) from passing.
Because components exchange ADO.NET datasets using XML, firewalls can allow datasets to pass.

Sunday, April 1, 2012

How to delete the duplicates with no primary key in SQLServer 2008

we have wonderful option CTE in SQLServer 2008 and can be used to delete all the duplicate records which are not having primary key. With Duplicate_table (Select Row_number() OVER (partition by ID order BY ID) as RowNumber FROM EMPLOYEE); DELETE FROM Duplicate_Table where RowNumber>1

Monday, March 22, 2010

Abut: Abstract class

public abstract class AbstractClass
{
public abstract void AbstractMethod1();
public abstract void AbstractMethod2();

}


public class classA : AbstractClass
{

public override void AbstractMethod1()
{
//some functionality goes here
}

public override void AbstractMethod2()
{
//some functionality goes here

}
}




public class classB : AbstractClass
{

public override void AbstractMethod1()
{
//some functionality goes here
}

public override void AbstractMethod2()
{
//some functionality goes here

}
}


//How can we remove AbstractMethod2 from classB without
//removing AbstractMethod2 method from AbstractClass and without
//removing the classB : AbstractClass relationship

Tuesday, March 9, 2010

What is difference between ExecuteReader, ExecuteNonQuery and ExecuteScalar?

ExecuteReader : Use for accessing data. It provides a forward-only, read-only, connected recordset.
ExecuteNonQuery : Use for data manipulation, such as Insert, Update, Delete.
ExecuteScalar : Use for retriving 1 row 1 col. value., i.e. Single value. eg: for retriving aggregate function. It is faster than other ways of retriving a single value from DB.

Thursday, March 4, 2010

What is the Difference between Web.config and Machine.config?

Scope:
Web.config => For particular application in IIS.
Machine.config = > For All the applications in IIS
Created:
Web.config => Created when you create an application
Machine.config => Create when you install Visual Studio
Known as:
Web.config => is known as Application Level configuration file
Machine.config => is known as Machine level configuration file
Location:
Web.config => In your application Directory
Machine.config => …\Microsoft.NET\Framework\(Version)\ CONFIG


Posted by: Neeks |dotnetfunda