Thursday, July 31, 2008

Short cut RUN prompt or Commends prompt keys

I know there are a lot of people who love using the RUN prompt or the COMMAND prompt rather than using the MMC control. Here are some of the short cut command for your regular use.Add/Remove Programs : appwiz.cpl Automatic Updates : wuaucpl.cpl Date and Time Properties : timedate.cpl Display Properties : control desktop Display Properties : desk.cpl Findfast : findfast.cpl Shuts Down Windows : shutdown Task Manager : taskmgr Wordpad : write Use the shortcuts...

Thursday, July 24, 2008

Convert string data into DataTime in Sql Server

In SQL Server, no direct funtion to convert interger string into time format. We need to do it by our own logic. See the below sample which convert integer string to datetime.DECLARE @DateTimeValue varchar(30), @DateValue char(8), @TimeValue char(6) SELECT @DateValue = '20080723', @TimeValue = '211957' SELECT @DateTimeValue = convert(varchar, convert(datetime, @DateValue), 111) + ' ' + substring(@TimeValue, 1, 2) + ':' + substring(@TimeValue, 3, 2) + ':' + substring(@TimeValue, 5, 2) SELECT ...

Monday, July 21, 2008

Visual Studio 2005 / 2008 short cut keys

Visual Studio 2005/2008 short cut keysUsing keyboard shortcuts is the best way to get things done faster in Visual Studio. Below are my favorite Visual Studio keyboard shortcuts.F12 : Go to definition of a variable, object, or function. SHIFT+F12 : Find all references of a function or variable.CTRL+ALT+L : View Solution Explorer. I use Auto Hide for all of my tool windows to maximize screen real estate. Whenever I need to open the Solution Explorer, it’s just a shortcut away. CTRL+M, O: Collapse to Definitions. This is usually the first thing I...

Saturday, July 19, 2008

Delegates in .NET

What is a Delegate?We can say delegates are a .NET object which points to a method that matches its specific signature or delegates are function pointers that point to function of matching signatures.Function pointers which are extensively used in c/c++ to points to a function holds only the memory address of the function, it doesn’t carry further information about the function parameters, return type etc.In other words delegates are function pointers that point to function of matching signatures. Function pointers which are extensively used in...

Monday, July 14, 2008

Convert DataTable to DataView in C# in VS 2008

The following sample will demonstrate the convertion from DataTable to DataView in C# in VS 2008. In VS 2008, DataView having one method which accept datatable as input parameter and it return the converted result as dataview by using DataView(). // Create dynamic data table. var dataTable = new DataTable(); // Create columns dataTable.Columns.Add("FirstName"); dataTable.Columns.Add("LastName"); dataTable.Columns.Add("Salary"); var dataRow = dataTable.NewRow(); ...

ValidateRequest in Page directive in asp.net

ASP.NET 2.0 validates form input values for potentially dangerous entries such as the '<' and '>' characters. When I enter the value '<' and '>' in textbox in .Net web form, it returns an error like 'Sys.WebForms.PageRequestManagerServerErrorException: An unkown erroroccured while processing the request on the server. The status code returned from the server was: 500'. So I search on google indicates the below solution for this :Add ValidateRequest = "false" in the Page directive.<%@ Page Language="vb" AutoEventWireup="false" Codebehind="sample.aspx.cs"Inherits="KannanDemo.sample"...

Saturday, July 12, 2008

Convert IEnumerable to DataTable in C#

Convert IEnumerable to DataTable in C#In LINQ, there is no option to casting IEnumerable to DataTable. We need to convert manually. For this, I have created one healper class which convert any type of IEnumerable to DataTable. Use the code below for this kind of requirements. using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using...

Adding Northwind Pub Database to SQL Server 2005

SQL Server 2005 doesn't include the Pubs and Northwind databases.You can click here to download (.msi) the latest version of Pub and Northwind sample databases . Install .msi file. It will create binary files (.mdf , .ldf) and SQL scripts (.sql) files.Installing sample databases from the Management Studio GUI: This method will use binary files.Copy .mdf and .ldf files back to SQL DATA folder like c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\. This path varies somewhat depending how many instances of SQL Server you have on your machine....

Wednesday, July 9, 2008

Open Enterprise Manager using keyboard shortcut

To open enterprise manager in SQL Server 2000 using keyboard shortcut: Microsoft Management Console (MMC)Start menu, Run, type "mmc"In the file menu, recent file list select "SQL Server Enterprise Manager.msc"If list is not there then try this oneSelect Start - Run. At the Open prompt enter: mmc Click OK Select File - Add/Remove Snap-in... Click Add... Select Microsoft SQL Enterprise Manager Click Add, then Close Click Ok to return to the mmc. Select File - Save As... Delete or rename the original (offending) file out the way. Save the new msc...

Job scheduler in SQL Server 2000

Job scheduler in SQL Server 2000 To create a SQL job scheduler in Sql Server 2000 and run it automatically in a particular interval. For this, we need to follow the steps given below:First we create one test database called 'KannanOrganization' in Sql Server 2000.Then we create one test table namely 'Employee' with the following table schema.Table Name : Employee-----------------------------------------------------------------------Column Name ...

Publishing Web Site in asp.net 2.0

Publishing Web Site in asp.net 2.0Compilation and Publishing in ASP.NET 2.0 is completely different than in ASP.NET 1.1. In ASP.NET 1.1, whether you debugged the code or ran it from a server, all of the .cs files were compiled into a single dll and the markup (.aspx and .ascx) remained seperate. This could often lead to problems if you declared a control in the markup but then didn't have a coresponding reference in the .cs file. All of this has...

Sunday, July 6, 2008

Join Operators in LINQ

Join Operators in LINQThere are two join operators: Join and GroupJoin. Join and GroupJoin provide an alternative strategy to Select and SelectMany.1. JoinThe Join operator performs an inner join, emitting a flat output sequence. The SQL equivalents of JOIN is INNER JOIN .For a sample, conside the people and roles objects below and see how to fetch the data from both the objects using JOIN.List people = new List { { ID = 1, LastName = "Kannan", FirstName= "Arjun", RoleId = 1}, { ID = 2, LastName...

Saturday, July 5, 2008

Projection Operators in LINQ

Projection Operators in LINQThere are two Projection Operators in LINQ namly 'Select' and 'SelectMany'. 1. Select : Just like SELECT in SQL, the Select operator specifies which elements are to be retrieved. The record or data retrival based on two models. One is element based selection and another one is Index based selection.public void KannanLINQDemo() { int[] digits = { 1, 5, 6, 2, 0 }; string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; var textNums = from n in digits ...

Restriction Operators in LINQ

Restriction Operator in LINQThere is only one restriction operator in LINQ is 'Where'. One of the most used LINQ operators is Where. It restricts the sequence returned by a query based on a predicate provided as an argument.The following code snippet uses Where to retrieve every element in a sequence that has FirstName equal to Arjun. In this samples we use Object Initilizer concept to create an people object. We can use this Where in two way.Element based retrival from the source sequencePosition (index) based retrival from the source sequenceFirst...

Standard Query Operators in LINQ

Standard Query Operators in LINQLINQ provides an API known as standard query operators (SQOs) to support the kinds of operations we’re commonly used to in SQL. You’ve already used C#’s select and where keywords, which map to LINQ’s Select and Where SQOs—which, like all SQOs, are actually methods of the System.Query.Sequence static class.In LINQ many SQOs are avilable whose all are grouped into 14 categories. They are listed below and click the list below to see the more details.Restriction OperatorProjection OperatorsJoin OperatorsGrouping OperatorOrdering...

Friday, July 4, 2008

Building blocks and Data sources of LINQ - Part 3

Building blocks and Data sources of LINQ - Part 3In the last few posts, I coverted few C# 3.0 features namly Object initialization Expressions, Extension Methods and Lamda Expressions and Expression Trees. In this post, I will cover the concept of Anonymous Types and Implicitly Typed Local Variables in details.5. Anonymous TypeAn anonymous type is a type that is declared without an identifer. You can use object initalizers without specifying the class that will be created with the 'new' operator. The compiler creates the anonymous type at compile...

Wednesday, July 2, 2008

Building blocks and Data sources of LINQ - Part 2

Building blocks and Data sources of LINQ - Part 2In the previous post, I coverted two new C# 3.0 features namly Object initialization Expressions and Extension Methods. In this post, I will cover the concept of Lamda Expressions and Expression Trees.3.Lamda Expressions This feature simplifies coding delegates and anonymous methods. Lambda expressions allow us to write functions that can be passed as arguments to methods. All lambda expressions use...

Building blocks and Data sources of LINQ - Part 1

Building blocks and Data sources of LINQ - Part 1The LINQ foundation consists of a set of building blocks including query operators, query expressions, and expression trees, which allow the LINQ toolset to be extensible.You can plug a wide array of data sources into LINQ, including File SystemActive DirectoryWMIWindows Event LogAny other Data Source or APIMicrosoft already offers more LINQ providersLINQ to Objects is an API that provides methods that represent a set of standard query operators (SQOs) to retrieve data from any object whose class...

Tuesday, July 1, 2008

How to insert data through stored procedure in LINQ

My last post describes how to create and fetch the data through stored procedure in LINQ. In this post, we will see how to insert the new data to the table, update or modify the existing information and delete the exisiting records through stored procedure in LINQ.Step 1 : Insert the data via stored procedure.First we should create DataContext classes for accessing the database. Click here to see how to create DataContext classes. Already, I have...