Wednesday, November 3, 2010

Sharepoint site 2010

I'm taking a sharepoint development course for free from FastSharePoint.com. Go to FastSharePoint.com for free SharePoint training.

Friday, March 19, 2010

How to Find Number of Columns in a Table

Below script find out how many columns are there in  a table


SELECT COUNT(1) 'No of Column(s)' FROM SYS.SYSCOLUMNS
WHERE ID = OBJECT_ID('TableName')


Happy Quering

Sleep for 1 min in SQL SERVER 2005

We just want to delay our query for one min.

To achieve that one we need write the below script

print getdate()
waitfor delay '00:01'
print getdate()


Output:

Mar 19 2010  6:37PM
Mar 19 2010  6:38PM



Happy Querying

Multiple Columns as Primary Key - SQL Server 2005

Steps to make multiple Columns of a table in SQL Server Management Studio

  1. Go to Table Design.
  2. Select a Column first to define it as Primary key.
  3. To select multiple columns, hold down the CTRL key while you click the other columns.
  4. Right-click the row selector for the column and select Set Primary Key.
  5. A primary key index, named "PK_" followed by the table name is automatically created.
Hope this helps you

Happy Coding

Wednesday, March 17, 2010

Update Tables Using Inner Join

You will come across the problem to update a table with the help of joining two tables.

Below is the steps to update a table using joins

  1. Perform a update say UPDATE
  2. Join the tables with condition say FIRSTTABLE AS A INNER JOIN SECONDTABLE AS B ON A.FIELDNAME = B.FIELDNAME
  3. Write the condition which is going to change or update say SET A.FIELDNAME=2, B.FIELDNAME=5
  4. If you have a where condition then add it say WHERE A.FIELDNAME=10
Combine the above steps and form a query as below
UPDATE
FIRSTTABLE AS A INNER JOIN SECONDTABLE AS B
ON A.FIELDNAME = B.FIELDNAME
SET A.FIELDNAME=2, B.FIELDNAME=5
WHERE A.FIELDNAME=10

Simply cool

Hope this helped you.

Happy Coding,
Kumar

Thursday, February 4, 2010

Advantages and Disadvantages of LINQ

LINQ (Language Integrated Query) is a Microsoft programming model and methodology that gives a formal query capabilities into Microsoft .NET-based programming languages.

It offers a compact, expressive, and intelligible syntax for manipulating data. The real value of LINQ comes is to apply the same query to an SQL database, a DataSet, an array of objects in memory and to many other types of data as well. It requires the presence of specific language extensions.

LINQ may be used to access all types of data, whereas embedded SQL is limited to addressing only databases that can handle SQL queries.

Below are the advantages and Disadvantages of LINQ


Advantages:

  1.  It is a cleaner and typesafety.
  2. It is checked by the compiler instead of at runtime
  3. It can be debugged easily.
  4.  It can be used against any datatype - it isn't limited to relational databases, you can also use it against XML, regular objects.
  5. It can able to query not just tables in a relational database but also text files and XML files.

Disadvantages:

  1. LINQ sends the entire query to the DB hence takes much network traffic but the stored procedures sends only argument and the stored procedure name. It will become really bad if the queries are very complex. 
  2. Preformance is degraded if we don't write the linq query correctly.
  3. If you need to make changes to the way you do data access, you need to recompile, version, and redeploy your assembly. 

Happy Coding and Learning

Friday, January 29, 2010

Convert Web Page to ASP.net User Control

Some situation comes into picture where we want to change the web page to User control.

Steps to convert asp.net web page to user control.

  1. Rename to the file extenstion (.aspx) to  a .ascx extension.
  2. Remove html, head, body, form tags from the page. 
  3. Change the "@ Page" directive to a "@ Control" directive. 
  4. Remove all attributes of the "@ Control" directive, except  Language, AutoEventWireup, CodeFile, and Inherits.
  5. Need to change the Inherits to have your new UserControl code behind file's name.
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserControlFilename.ascx.cs"  Inherits="UserControlFileName" %>
  6. Close and re-open the file to make squiggles go away.
  7. Open the code behind file and change the class it inherits from to UserControl, and the class name to match your .ascx file.
    public partial class UserControlFileName : System.Web.UI.UserControl
Hope this helps for some body.

Wednesday, January 27, 2010

What is Multi-Targeting in .net?

In the previous version of Visual Studio, each Visual Studio release supports to a specific version of the .NET Framework. For example, VS 2002 only worked with .NET 1.0, VS 2003 only worked with .NET 1.1, and VS 2005 only worked with .NET 2.0.

Now with the major change in VS2008 is to support "Multi-Targeting "
Visual Studio 2008 is used to create projects that target .NET Framework version 2.0, 3.0, or 3.5. is what we call as "Multi-Targeting".

Tuesday, January 12, 2010

What is Tracing and how to enable it?

Tracing helps understand which control uses more view state,  start/end of PreInit etc. This type of information appears at the bottom of the page.

Tracing can be enable at Page level and Application Level


Page Level: You can add a Trace="true" in the page directive.
<%@ Page Language="C#"  Trace="true" %>

Application Level: The user can enable Application level tracing in the Web.config file.
By doing this the user will get trace information for all pages in your application.


<configuration>
                <system.web>
                       <trace enabled="true" />
                </system.web>
</configuration>



Happy Tracing.

Tuesday, December 29, 2009

C# 3.0 new Features - Part 2

Continuing from part 1, here I will go one more step further and explain about Lambda Expression basics in C# 3.0 which will help us in writing a LINQ query.

Lambda Expressions -  Part 1

In C# 2.0 we used to write anonymous delegate method that helped us in minimizing the code writing.

Example: The below code snippet that searches for a Employee based on the Empname field using predicates in C# 2.0

class Employee
    {
        private string empName;
        public string EmpName
        {
            get
            {
                if (empName != null)
                {
                    return empName;
                }
            }
            set
            {
                empName = value;
            }
        }
    }

Now we will get the employee details from GetAllEmployees() function which is written in Data Access Layer (DAL) Layer.

List <Employee> myEmployees = GetAllEmployees();

We will use System.Collection.List<T>.FindAll to search for the Employee based on EmpName.

MSDN has following information on the FindAll method.

Retrieves all the elements that match the conditions defined by the specified predicate.


We will now find the employee with the employee name filter.
List <Employee> employee = myEmployees.FindAll( new Predicate<Employee>(EmpNameFilter));
//Defination for EmpNameFilter
static bool EmpNameFilter(Employee e)
{
            e.EmpName = “Kumar”
}

We will rewrite the above code using C# 2.0 Anonymous method.
List <Employee> employee = myEmployees.FindAll(delegate(Employee e) {return e.EmpName=”Kumar”})

We have reduced some coding steps with the help of anonymous method, we still able to reduce the coding steps with the help of Lambda Expression

List <Employee> employee = myEmployees.FindAll(e=>e.EmpName==”Kumar”);

So basically when we have a lambda expression defined then we are inherently using delegates. Its bit difficult for the first time but over a period of time we will feel happy using it.

Accoding to MSDN the following information for Lambda Expression.

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

delegate int del(int i);
static void Main(string[] args)
{
    del myDelegate = x => x * x;
    int j = myDelegate(5); //j = 25
}

The => operator has the same precedence as assignment (=) and is right-associative.
Lambdas are not allowed on the left side of the is or as operator.

Hope this article helps you to understand the basic about Lambda Expression.

Stay tuned for Lambda Expression Part 2.

Happy Coding and Leaning.

blogger templates | Make Money Online