What's New In Donet 3.5

  • Support for enabling existing ASP.NET 2.0 pages for AJAX
  • Creation of ASMX & WCF based web services and consuming them from AJAX Library
  • ASP.NET server side application services like authentication, roles management exposed as web services
  • ASP.NET Merge Tool - a new tool for merging pre-compiled assemblies
  • New ListView control which supports edit, insert, delete, sorting & paging
  • ASP.NET integrated with core IIS 7.0 which makes ASP.NET services like authentication & caching available for other content types also.
  • Microsoft AJAX Library to support AJAX based web development

ADO.NET

ADO.NET 1.x
  • As an evolution to ActiveX Data Objects (ADO) Technology, it has been part of .net framework right from version first. The framework to access data stores from managed code. It supports two kinds of architectures :
  • Fast, forward and connected model for read only access using Readers and Updates using commands.
  • Disconnected model using DataSets where you want to cache data locally and do aggressive manipulations on data.

ADO.NET 2.0
  • Base-Class-Based Provider Model : While in ADO.NET 1.x the db specific providers implemented the base interface, 2.0 comes with a base implementation which implements the common functionality across databases.
  • Tracing : Generalized Tracing and Instrumentation integrated with ADO.NET to ease diagnostics.
  • Total Four Providers : For SQL Server, Oracle, Ole DB and ODBC
  • Asynchronous Command Execution : Support asynchronous command execution using Begin and End methods for long running commands.
  • Multiple Active Resultsets (MARS) : In 1.x it was possible to have only one active resultset on a connection. With 2.0 you can have multiple active resultsets on a single connection provided resultsets have been populated from different commands. Available only for SQL Server 2005
  • Data change notification : For SQL Server 2005 and with SQL Server Service Broker, applications can register for notifications whenever data changes in db.
  • Batch Updates : Batch Updates supported from Datasets.
ADO.NET vNext
  • Entity Framework : Based on Entity Data Model (EDM) exposes logical relational data model as conceptual business model and provides Enity SQL (ESQL) to work directly against entities.
  • Codename "Jasper" : A tool to create data-serving applications which generate data classes at runtime instead of design time code generation. It uses Enity Framework.
  • Codename "Astoria" : Enables applications to expose data as data services over http in formats like XML. Helps in integration of client applications with data stores over web without developing a complicated server layer.
  • LINQ to SQL (formerly known as DLinq) : Enables LINQ to work directly on SQL db objects like tables, rows etc.
  • LINQ to Dataset : Use LINQ to directly query datasets.
  • LINQ to Entities : Like ESQL, LINQ can also be used to query Entities exposed by entity framework.

An Introduction About LINQ

New to C# 3.0. LINQ (Language Integrated Query) extends the query capabilities of c# and Visual Basic in terms of querying and updating data using language syntax on any kind of data store. With Orcas the data stores mainly supported are in-memory objects, XML , SQL Server db objects, ADO.NET datasets. In future LINQ will also support querying on Entities exposed as part of ADO.NET Entity framework.
It supports compile time checking for syntax errors and type safety.
LINQ provides complete query language for any collection that implements IEnumerable or IQueryable. For in-memory objects to be enabled for LINQ, the object type should implement IEnumerable. For LINQ to XML, SQL and Datasets the underlying provider converts the target objects to IEnumerable based collections.
Let’s see LINQ in action. Currently the most recommended way of trying LINQ id Beta 1 of Orcas which has LINQ framework integrated with it.
Consider the program below :

using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
string[] words = new string[5]
{ "Word1", "World", "Word2", "Word3", "Word4" };
IEnumerable wordQuery = from word in words where word == "World" select word; foreach (string name in wordQuery)
{
Console.WriteLine("Hello " + name);
}
}
}
}

Output :
Hello World
In above program we query the list of words for a particular word ‘World’ and then prints ‘Hello World’ the number of times the word is found. Instead of using ‘if’ keyword, LINQ adds the capability of querying the local variables using very familiar SQL type querying capabilities.


With LINQ comes lot of new concepts which I will cover in detail very soon, but here is the list :
1. Immediate & Deferred execution of queries.

2. Forced Immediate Execution

3. Standard Query Operator Extension Methods

What's New in CSharp 3.0

Here is a point wise summary of features introduced newly in C# 3.0


Implicitly Typed Local Variables
Local variables can be declared as type ‘var’ which means compiler to determine the actual type based on the data by which its is initialized.

  • var i = 10; // i is created of type int
  • var name = “MyName” ; // name is created of type string
  • can only be used when declared and initialized in same statement.
  • Cannot be initialized to null.
  • Cannot be used as class members.
  • Mostly used to store anonymous types as in LINQ based programming.

Object & Collection Initializers

  • Allow assigning values to any accessible members or properties of a type at the time of initiation without invoking the constructor with parameters.
  • The default constructor gets executed before assigning the values.
  • E.g. Coordinate c1 = new Coordinate {x=1 , y=2};
  • Used in LINQ query expressions along with anonymous types.
  • Collection Initializers use Object Initializers to specify multiple elements of collection without calling Add method multiple times.

Extension Methods

  • Allows adding new methods to existing types without modifying the existing type.
  • Are special kind of static methods but are called as if they are instance methods.
  • The first parameter passed to Extension methods specifies to which type they operate on preceded by ‘this’ keyword.
  • They cannot access the private variables of type which they are extending.
  • Extension Methods need to defined in a non-nested and non-generic static class.
  • Instance methods take priority over extension methods in case they have same signature.

Anonymous Types

Are of class types which can have only public read-only properties as their members. No other class members like methods are allowed.

  • They are of reference types and are derived from ‘Object’ class.
  • Internally compiler gives them the name but its not accessible by application code.
    They have a method scope.
  • Can be initiated directly e.g. new { property1=1, property2=”Hello World”};

Lambda Expressions
Very similar to anonymous methods introduced in C# 2.0.

  • Its an inline expression or statement block which can be used to pass arguments to method call or assign value to delegate.
  • All lambda expression use lambda operator => where the left side denotes result and right contains statement block or expression.

Auto-Implemented Properties

  • Helps in simplifying property declaration in cases where there is no custom logic required in accessors methods.
  • E.g. public int Price {get; set;};
  • Internally compiler creates an anonymous field for assigning values.

What's New in DotNet

ASP.NET


  • Support for enabling existing ASP.NET 2.0 pages for AJAX
    Creation of ASMX & WCF based web services and consuming them from AJAX Library
  • ASP.NET server side application services like authentication, roles management exposed as web services
  • ASP.NET Merge Tool - a new tool for merging pre-compiled assemblies
  • New ListView control which supports edit, insert, delete, sorting & paging
  • ASP.NET integrated with core IIS 7.0 which makes ASP.NET services like authentication & caching available for other content types also.
  • Microsoft AJAX Library to support AJAX based web development

Base Classes & CLR

  • Support for CSharp 3.0 including LINQ.
  • HashSet : A high performance collection of type set.
  • Time Zone Improvements : to develop applications which operate in multiple time zones
  • Minor Improvements in Threading, Reflection and controlling the GC behavior

Others

  • Client Application Services : All windows based application to use ASP.NET login, roles and profile services hosted on central server.
  • Occasionally Connected Services (OCS) : keeps windows application's local and remote data in sync.
  • 'Silver' : code name for a new technology which unifies WF and WCF
    WCF Syndication : WCF services exposing syndication feeds. Supports Atom 1.0 and RSS 2.0

Celerating 10 Years Of XML

Check out the official celebration pages : http://www.w3.org/2008/xml10/

XML in 10 points

  • XML is for structuring data
  • XML looks a bit like HTML
  • XML is text, but isn't meant to be read
  • XML is verbose by design
  • XML is a family of technologies
  • XML is new, but not that new
  • XML leads HTML to XHTML
  • XML is modular
  • XML is the basis for RDF and the Semantic Web
  • XML is license-free, platform-independent and well-supported

SOA Development For WCF

If you are into developing and consuming services in SOA environment , Interoperability is something which is assumed. Interoperability is best achieved by following standards.

WCF provides a system binding called ‘BasicHttpBinding’ which conforms to the minimum requirement for having a standard compliant web service as specified by WS-I organization.

'BasicHttpBinding’ of WCF 3.5 is compliant to Basic Profile 1.1 standard of Web Service.
Basic Profile 1.1 in turn is the umbrella term which list down versions/editions of various underlying standards/specifications that need to be supported.

Following is the list of standards which Basic Profile 1.1 contains :
  • Extensible Markup Language (XML) 1.0 (Fourth Edition)
  • Extensible Markup Language (XML) 1.0 (Second Edition)
  • Namespaces in XML
  • RFC2246: The TLS Protocol Version 1.0
  • RFC2965: HTTP State Management Mechanism
  • Simple Object Access Protocol (SOAP) 1.1
  • UDDI Version 2 XML Schema
  • UDDI Version 2.03 Data Structure Reference, Dated 19 July 2002
  • UDDI Version 2.03 Data Structure Reference, Section 7
  • WSDL 1.1
  • WSDL 1.1 Binding Extension for SOAP 1.2
  • XML Schema Part 1: Structures
Basic Profile 1.2 is under progress.

Understanding the content specifications of Basic Profile is more important because each of
them evolve independently.

Current Versions of some them are :

  • XML 1.1 Second Edition
  • WSDL 2.0
  • SOAP 1.2

Generate Office 2007 documents using OpenXml SDK

Check out my latest article :
Generate Office 2007 documents using OpenXML SDK
  • Overview of Office 2007 documents format and OpenXML SDK.
  • Step by Step instructions on how to generate Office 2007 documents using OpenXML SDK

How to call C or C++ DLL in C#

You can call functions in a dll using the following simple method

  1. you must know the function prototype (name of the function and its parameters and its return type)
  2. In your code use a code like the following where DllImport Specfies the dll where the function exists and the line under it specifies the function prototype.

using System.Runtime.InteropServices;
namespace myNameSpace
{
public class MyClass
{
[DllImport("DLLPath.DLL")]public static extern int FunctionName(int Argument1, bool Argument2);
}
}

an Example for using DllImport is to use a Windows API functionwe will call a a function that can make you copy a file, its name is CopyFile and it is loacted in Kernel32.dll
this code sample demonstrate how to call this functionusing

System.Runtime.InteropServices;
namespace FileSystemClasses
{
public class FileSystem
{
[DllImport("Kernel32.DLL")]public static extern bool CopyFile(string strSourcePath, string strTargetPath, bool bOverwrite);public void TestDll(){FileSystem.CopyFile("c:\\a.txt", "c:\\b.txt", true);
}
}
}

there are other options that can be used with DllImport directive which gives some advanced options and more control which can be explained in another articleFor a list of Windows API Functions according to their usage go to:

Office SharePoint Server Development - What's Needed?

To begin playing with SharePoint Development you will need:- Windows Server 2003.

Install Windows SharePoint Services 3.0 (WSS) or Microsoft Office SharePoint Server (MOSS)

Visual Studio 2005

Calling .NET DLL from Classic ASP Page

I needed to call a .NET DLL from some ASP pages, the DLL was for a search engine and the ASP site was serving as its interface i have done some research and found a way to deal with this the steps are as following:

  • Create a DLL in .NET and be aware that only one class will be used from it (I wasn't able to use any other class than the first one in the dll)
  • build the project
  • Open .NET Command prompt from the tools of .NET located in the Start Menu Shortcuts of .NET
  • Run the following command:Regasm [Your DLL Path] /codebase
  • in your ASP page create an object from your DLL classset Inst = Server.CreateObject("NameSpace.ClassName")replace the NameSpace by your DLL NameSpace and the ClassName by your class nameNote:this code runs in VBScript and it would defer a little if JScript was used
  • You can call a function from your dll using the instance created like:Inst.CallFunction()

VBScript and COM (The Array Dilemma)

its my second day to deal with COM and VBScript and i have faced the problem of passing arrays to and from .NET DLL serving as a COM Component, i described how to do this in the previous postA problem arises when trying to return an array from a function or pass array to it

How to reproduce:

  • you have a .NET DLL using it as a COM Object
  • you have a function in a class that returns an array of any type
  • you create an instance of this class using CreateObject
  • you call the function that returns an array
  • test the array using IsArray() and VarType() and Ubound()
  • the object is truly an array and its VarType() denots its type and Ubound() gives its valid size
  • then you an item in the array it will give you error "Type Mismatch" !!

Why:

  • VBScript datatypes are all based on a basic type called "Variant" which may corresponds to the "Object" data type in .NET
  • Its logic that if VBScript can know the array type which it can access, so why when trying to access a certain item in the array it gives "Type Mismatch" !!!!
  • I think that this is due to a diffrence in implementing and viewing the array from the prespective of .NET and the prespective of VBScript
  • Some solutions on the newsgroups said that you must return your datatype as an Object and this worked in some cases
  • The version of the VBScript processor DLL may have also an influnce in producing this problem

Coding Style

coding style is an important factor in producing an efficient code that can be reused or modified eaisly.I will review here basic hints in coding styles:

naming variables: best way to name a variable is to choose first an abreviation for it based on its type like "str" for "String" and "num" for "Numebers", then add a descriptive name for the variable ex: if you are declaring a variable for the Monthly Income its name may be like "numMonthlyIncome", take care that to make the variable readable Start every descriptve word in it with a capital letter and the varaiable abbreviation must be in small letters.

naming Functions: try to name Functions so that describe their operation and target and avoid ambigous names, and concentrate on choosing a name that describes the output not the input since the input will be described in the parameteres declaration in the function ex: int GetAverageIncome(string strEmployeeName).

Return Codes: it is a coding style where all the functions in the code always returns an integer value describing the status of the result or any other related message like errors that may occure or confirmation messages or you can combine between the return value of a function and its return codes like in the example of the previous function declaration, we know that an average value of an income must be always a postive value so we can return negative values describing error messages like -1 for "That employee does not exist in the database" and so on.

PDF Files

I found a fantastic class library project to edit and create PDF files its name is "IText_Sharp" which is an import for the original project "IText" from Java to C#, Check it out if you need to edit or create PDF files.www.sourceforge.net/projects/itextsharp/

Invalid character value for cast specification

If you catch this error and you are trying to use a DateTime Value with SQL Server then check that your date in this range:1/1/1753 to 31/12/9999

C# Invalid Cross Thread Operation

In .NET Framework 2.0 with default settings you can not change a Windows Control Property from an external thread, and if you try to do that you will get the following Exception"Invalid Cross-Thread Operation"to avoid this exception you can disable the checking for invalid Cross-Thread Operation by setting this static Property to false:Control.CheckForIllegalCrossThreadCalls = false;This settings is not recommended it is done only to avoid the exception appearing while debugging, it may cause serious problems if you disabled it (its done mainly to warn you while you debug your application).To See other techniques to avoid this problem,see:

http://weblogs.asp.net/justin_rogers/archive/2004/10/08/240077.aspx

http://blogs.wwwcoder.com/amachin/archive/2004/12/15/1146.aspx

What is a Class?


A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations.
public class Student
{

}

According to the sample given below we can say that the student object, named objectStudent, has created out of the Student class.

Student objectStudent = new Student();

What is an Object?

An object can be considered a "thing" that can perform a set of related activities. The set of

activities that the object performs defines the object's behavior. For example, the hand can grip

something or a Student (object) can give the name or address.

In pure OOP terms an object is an instance of a class.

What is OOP?

OOP is a design philosophy. It stands for Object Oriented Programming. Object-Oriented

Programming (OOP) uses a different set of programming languages than old procedural

programming languages (C, Pascal, etc.). Everything in OOP is grouped as self sustainable

"objects". Hence, you gain re-usability by means of four main object-oriented programming

concepts.

In order to clearly understand the object orientation, let’s take your “hand” as an example. The

“hand” is a class. Your body has two objects of type hand, named left hand and right hand. Their

main functions are controlled/ managed by a set of electrical signals sent through your shoulders

(through an interface). So the shoulder is an interface which your body uses to interact with your

hands. The hand is a well architected class. The hand is being re-used to create the left hand and

the right hand by slightly changing the properties of it.

What is Software Architecture?


Software Architecture is defined to be the rules, heuristics and patterns governing:
  • Partitioning the problem and the system to be built into discrete pieces
  • Techniques used to create interfaces between these pieces
  • Techniques used to manage overall structure and flow
  • Techniques used to interface the system to its environment
  • Appropriate use of development and delivery approaches, techniques and tools.

Explain SQL

The Structured Query Language is used for operating the data stored in Relational Database Management Systems (RDBMS). SQL provides commands through which data can be extracted, sorted, updated, deleted and inserted.

Most of the important and common SQL statements are supported by RDBMS like MySQL, Informix, DB2, Oracle, MS SQL Server, MS Access, Sybase, etc.

What is DDL, DML, DCL, TCL in SQL ?

The Data Definition Language (DDL) includes,

CREATE TABLE - creates new database table

ALTER TABLE - alters or changes the database table

DROP TABLE - deletes the database table

CREATE INDEX - creates an index or used as a search key

DROP INDEX - deletes an index

The Data Manipulation Language (DML) includes,

SELECT - extracts data from the database

UPDATE - updates data in the database

DELETE - deletes data from the database

INSERT INTO - inserts new data into the database

The Data Control Language (DCL) includes,

GRANT – gives access privileges to users for database

REVOKE – withdraws access privileges to users for database

The Transaction Control (TCL) includes,

COMMIT – saves the work done

ROLLBACK - restore the database to original since the last COMMIT

Define select statement

The SELECT statement is used to select data from a table, basically the SELECT statement will

have three clauses,

SELECT - specifies the table columns retrieved

FROM - specifies the tables to be accessed

WHERE - specifies which rows in the FROM tables to use

The WHERE clause is optional and commonly called as Condition, if it is not used all the table

rows will get displayed.

Example :

Select EmployeeName, EmployeeID from Employees;

This Query will list the Employee Name and Employee ID column from table

“Employees”

Select * from Employees;

This Query will list all the columns in the entire table “Employees”

Select Distinct Department from Employees;

This Query select only the different values from column named “Department” in

“Employees” table

Select EmployeeName, EmployeeID from Employees where City is NULL

This Query selects the list of Employees who have not specified their city name in the

table, if you want to list the Employees who specified the city in table use “where city

is NOT NULL”.

How to use where clause in select statements

The WHERE clause selects data from a table on conditional basis,
Example :
Select EmployeeID from Employees where Position = 'Manager';

This Query displays the ID Numbers of all Managers from the table “Employees” and make sure that any text that appears in the statement is surrounded by single quotes (')

Select EmployeeID from Employees where Salary >= 50000;

This Query displays the ID Numbers of all Managers from the table “Employees” who gets salary of 50000 and above

Select * from Employees where EmployeeName like ‘d%’

This Query will display the Employee names that start with ‘d’

Select * from Employees where EmployeeName like ‘%m’

This Query will display the Employee names that end with ‘m’

Select * from Employees where EmployeeName like ‘%la%’

This Query will display the Employee names that contain the word ‘la’

Select * from Employees where EmployeeName in (‘Jerry’ , ‘Sam’)

This Query will display the Employee names starting with ‘Jerry’ and ‘Sam’

Select * from Employees where EmployeeName between ‘Jerry’ and ‘Sam’

This Query will display the Employee names alphabetically between ‘Jerry’ and ‘Sam’

Select * from Employees where EmployeeName not between ‘Jerry’ and ‘Sam’

This Query will display the Employee names outside the range of ‘Jerry’ and ‘Sam’
Some commonly used logical operators in SQL are,
= “Equal”
<> or != “Not Equal”
< “Less than”
> “Greater than”
<= “Less than or equal to”
>= “Greater than or equal to”
BETWEEN “Used to search between an inclusive range”
LIKE “Used to Search for a pattern”
IN “Used to return based on the Exact value known”

Define select into statement in SQL

The SELECT INTO statement is used to select data from a database table and to insert it to a different table at the same time.

Example :

Select * into Departments from Employees

This Query will select data from “Employees” table and insert into “Departments.

Define insert into statement


The INSERT INTO statement is used to insert new rows in a database table.

Example :
Insert Into Employees values ( ‘Edward’, ‘14991’, ’16 Indira Nagar’, ‘Chennai’ )

This Query will insert data into “Employee Name”, “Employee ID”, “Address”, “City” columns of “Employees” table

The data can be inserted in specified columns like,
Insert Into Employees ( EmployeeName, City ) values ( ‘Andrew’, ‘Chennai’ )

This Query will insert data into “Employee Name” and “City” column of “Employees” table.

Define update statement

The UPDATE statement is used to modify the data in a database table.

Example :

Update Employees set EmployeeName = ‘Peter Heines’ where EmployeeName = ‘Peter’

This Query will modify the Employee name “Peter” into “Peter Heines”

The data can be updated in several columns like,

Update Employees set Address = ‘134 Gandhi Nagar’ , City = ‘Bangalore’ where EmployeeName

= ‘James Roguer’

This Query will modify the Address and City of the Employee with name ““James Roguer”

Define delete statement


The DELETE statement in used to delete the rows in a database table.

Example :

Delete from Employees where EmployeeName = ‘Peterson’
This Query will delete the row that is having employee name as “Peterson”
All the rows in a table can be deleted like,
Delete * from Employees

Or

Delete from Employees
This Query will delete all the rows in “Employees” table

Define order by statement

The ORDER BY clause is used to sort the output in the specified manner like ascending or

descending.

Select EmployeeName, EmployeeID from Employees order by EmployeeName Desc

This Query will display the Employee names in reverse alphabetical order

Select EmployeeName, EmployeeID from Employees order by EmployeeName Desc, EmployeeID Asc

This Query will display the Employee names in reverse alphabetical order and the Employee ID in

alphabetical order.

What is the difference between UNION and UNIONALL commands in SQL

The UNION command is used to select the related data from two different tables, while using

the UNION command all the selected columns have to to be of the same data type.

Example :

Select EmployeeName from Employees unionSelect EmployeeName from Department

This Query will display only the distinct Employee names in Employees and Department Tables.

The UNION ALL command is similar to UNION command, but it displays all the values in the

both the tables.

Example :

Select EmployeeName from Employees union allSelect EmployeeName from Department

This Query will display all the Employee names in Employees and Department Tables.

Define AND & OR conditions in SQL

The AND & OR is used to join two or more conditions in a WHERE clause

The AND operator displays a row if ALL the conditions listed are true.

Example :

Select * from Employees where EmployeeName = ‘Steve’ and City = ‘Bangalore’

This Query will display the each person with EmployeeName equal to “Steve” and City equal to

“Bangalore”

The OR operator displays a row if ANY of the conditions listed are true

Example :

Select * from Employees where EmployeeName = ‘Steve’ or City = ‘Bangalore’

This Query will display the each person with EmployeeName equal to “Steve” or City equal to

“Bangalore”.

Define IN operator in SQL

The IN operator is used to compare a column with one or more value. It is similar to

OR condition.

Example :

Select EmployeeName, EmployeeIDfrom Employeeswhere City in (‘Chennai’,

‘Bangalore’)

This Query will display the Employee Name, Employee ID only from city “Chennai”

and “Bangalore”.