I'm taking a sharepoint development course for free from FastSharePoint.com. Go to FastSharePoint.com for free SharePoint training.
Wednesday, November 3, 2010
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
Posted by Kumar at 11:21 AM 0 comments
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
Posted by Kumar at 6:43 AM 0 comments
Labels: SQL
Multiple Columns as Primary Key - SQL Server 2005
Steps to make multiple Columns of a table in SQL Server Management Studio
- Go to Table Design.
- Select a Column first to define it as Primary key.
- To select multiple columns, hold down the CTRL key while you click the other columns.
- Right-click the row selector for the column and select Set Primary Key.
- A primary key index, named "PK_" followed by the table name is automatically created.
Happy Coding
Posted by Kumar at 5:52 AM 0 comments
Labels: SQL
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
- Perform a update say UPDATE
- Join the tables with condition say FIRSTTABLE AS A INNER JOIN SECONDTABLE AS B ON A.FIELDNAME = B.FIELDNAME
- Write the condition which is going to change or update say SET A.FIELDNAME=2, B.FIELDNAME=5
- If you have a where condition then add it say WHERE A.FIELDNAME=10
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
Posted by Kumar at 5:15 AM 0 comments
Labels: SQL
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:
- It is a cleaner and typesafety.
- It is checked by the compiler instead of at runtime
- It can be debugged easily.
- It can be used against any datatype - it isn't limited to relational databases, you can also use it against XML, regular objects.
- It can able to query not just tables in a relational database but also text files and XML files.
Disadvantages:
- 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.
- Preformance is degraded if we don't write the linq query correctly.
- 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
Posted by Kumar at 12:32 PM 0 comments
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.
- Rename to the file extenstion (.aspx) to a .ascx extension.
- Remove html, head, body, form tags from the page.
- Change the "@ Page" directive to a "@ Control" directive.
- Remove all attributes of the "@ Control" directive, except Language, AutoEventWireup, CodeFile, and Inherits.
- 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" %> - Close and re-open the file to make squiggles go away.
- 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.
Posted by Kumar at 9:15 AM 0 comments
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".
Posted by Kumar at 12:24 AM 0 comments
Labels: Asp.net Questions and answers
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.
Posted by Kumar at 4:20 AM 0 comments
Labels: Tips
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.
For more information : http://msdn.microsoft.com/en-us/library/fh1w7y8z.aspx
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)
{
int j = myDelegate(5); //j = 25
}
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.
Posted by Kumar at 11:11 PM 0 comments
Subscribe to:
Posts (Atom)