Sunday, November 30, 2008

Maximum Capacity Specifications for SQL Server 2005

# Batch size : -> 65,536 * Network Packet Size
# Bytes per short string column : -> 8000
# Bytes per text, ntext, image, varchar(max), nvarchar(max), varbinary(max), or XML column : -> 231 -1 bytes/p>
# Bytes per GROUP BY, ORDER BY : -> 8060
# Bytes per index : -> 900
# Bytes per foreign key : -> 900
# Bytes per primary key : -> 900
# Bytes per row : -> 8060
# Bytes in source text of a stored procedure : -> Lesser of batch size or 250 MB
# Clustered indexes per table : -> 1
# Columns in GROUP BY, ORDER BY : -> Limited only by number of bytes
# Columns or expressions in a GROUP BY WITH CUBE or WITH ROLLUP statement : -> 10
# Columns per index : -> 16
# Columns per foreign key : -> 16
# Columns per primary key : -> 16
# Columns per base table : -> 1024
# Columns per SELECT statement : -> 4096
# Columns per INSERT statement : -> 1024
# Connections per client : -> Maximum value of configured connections
# Database size : -> 1,048,516 terabytes
# Databases per instance of SQL Server : -> 32767
# Filegroups per database : -> 32767
# Files per database : -> 32767
# File size (data) : -> 32 terabytes
# File size (log) : -> 32 terabytes
# Foreign key table references per table : -> 253
# Identifier length (in characters) : -> 128
# Instances per computer : -> 50
# Length of a string containing SQL statements (batch size) : -> 65,536 * Network packet size
# Locks per connection : -> Maximum locks per server
# Locks per instance of SQL Server : -> Up to 2,147,483,647
# Nested stored procedure levels : -> 32
# Nested subqueries : -> 32
# Nested trigger levels : -> 32
# Nonclustered indexes per table : -> 249
# Objects concurrently open in an instance of SQL Server : -> 2,147,483,647 per database (depending on available memory)
# Objects in a database : -> 2147483647
# Parameters per stored procedure : -> 2100
# Parameters per user-defined function : -> 2100
# REFERENCES per table : -> 253
# Rows per table : -> Limited by available storage
# Tables per database : -> Limited by number of objects in a database
# Tables per SELECT statement : -> 256
# Triggers per table : -> Limited by number of objects in a database
# UNIQUE indexes or constraints per table : -> 249 nonclustered and 1 clustered

Friday, November 28, 2008

OOPS Concepts:

1) Encapsulation: Wrapping up of data and methods in to a
single unit is called as encapsulation.
Protecting our data


2) Abstraction: Hidding our irrelavance data

3) Inheritence: Process of Aquiring properties from one
object to another without changes.

4) Polymorphism: Process of aquiring properies from one
object to anotherwith changes.Different behaviors at diff. instances
There are two types of polymorphisms.
i)Compile-time polymorphism:what object will be assigned to
the present variable.This will be evaluated at compile time.
This is known as compile-time polymorphism.
ii)Run-time polymorphism:what object will be assigned to the
present variable.This will be evaluated at runtime depending
on condition.This is known as Run-time polymorphism.

5) Message Passing:message passing is possible from one
object to another.

6) Robust and Secure: every object is strong one.
every object is secure one with their access specifiers.


Abstract, Sealed, and Static Modifiers in C#.

C# provides many modifiers for use with types and type members. Of these, three can be used with classes: abstract, sealed and static.

abstract
Indicates that a class is to be used only as a base class for other classes. This means that you cannot create an instance of the class directly. Any class derived from it must implement all of its abstract methods and accessors. Despite its name, an abstract class can possess non-abstract methods and properties.

sealed
Specifies that a class cannot be inherited (used as a base class). Note that .NET does not permit a class to be both abstract and sealed.

static
Specifies that a class contains only static members (.NET 2.0).


Virtual keyword

The virtual keyword allows polymorphism too. A virtual property or method has an implementation in the base class, and can be overriden in the derived classes.

To create a virtual member in C#, use the virtual keyword:

public virtual void Draw()

To create a virtual member in VB.NET, use the Overridable keyword:

Public Overridable Function Draw()

Override keyword

Overriding is the action of modifying or replacing the implementation of the parent class with a new one. Parent classes with virtual or abstract members allow derived classes to override them.

To override a member in C#, use the override keyword:

public override void CalculateArea()

To override a member in VB.NET, use the Overrides keyword:

Public Overrides Function CalculateArea()


What's the difference between override and new in C#?

This is all to do with polymorphism. When a virtual method is called on a reference, the actual type of the object that the reference refers to is used to decide which method implementation to use. When a method of a base class is overridden in a derived class, the version in the derived class is used, even if the calling code didn't "know" that the object was an instance of the derived class. For instance:
public class Base
{
public virtual void SomeMethod()
{
}
}

public class Derived : Base
{
public override void SomeMethod()
{
}
}

...

Base b = new Derived();
b.SomeMethod();


will end up calling Derived.SomeMethod if that overrides Base.SomeMethod.

Now, if you use the new keyword instead of override, the method in the derived class doesn't override the method in the base class, it merely hides it. In that case, code like this:
public class Base
{
public virtual void SomeOtherMethod()
{
}
}

public class Derived : Base
{
public new void SomeOtherMethod()
{
}
}

...


Base b = new Derived();
Derived d = new Derived();
b.SomeOtherMethod();
d.SomeOtherMethod();


Will first call Base.SomeOtherMethod , then Derived.SomeOtherMethod . They're effectively two entirely separate methods which happen to have the same name, rather than the derived method overriding the base method.

If you don't specify either new or overrides, the resulting output is the same as if you specified new, but you'll also get a compiler warning (as you may not be aware that you're hiding a method in the base class method, or indeed you may have wanted to override it, and merely forgot to include the keyword).

Monday, November 24, 2008

GridView Search Revisited

in .aspx
Enter Search Keyword:
asp:TextBox ID="txtSearchBox" runat="server"
asp:Button ID="Btn_Search" OnClick="Search" runat="server" Text="Search" />
asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="false" AllowPaging="True" Font-Size="Large" OnPageIndexChanging="gvProducts_PageIndexChanging" PageSize="10">
Columns>
asp:TemplateField HeaderText="Product Name">
ItemTemplate>
asp:Label ID="lblProductName" runat="server" Text = '<%# SearchKeyWord( searchWord,(string) Eval("ProductName") ) %>' />
/ItemTemplate>
/asp:TemplateField>
/Columns>
/asp:GridView>
asp:Panel ID="Panel1" runat="server" Height="50px" Width="263px">


.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page
{
protected string searchWord = String.Empty;
private const int PAGE_SIZE = 10;

private Hashtable hMatches = new Hashtable();

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}

CreateLinks();


}

private void CreateLinks()
{
Hashtable myHashTable = ViewState["MyHashTable"] as Hashtable;

if(myHashTable != null && myHashTable.Count > 0)
{

foreach (object key in new ArrayList(myHashTable.Keys))
{
LinkButton link = new LinkButton();
link.Command += new CommandEventHandler(link_Command);
link.CommandArgument = key.ToString();
link.Text = String.Format("There are {0} results on page {1}",myHashTable[key].ToString() , (Convert.ToInt32(key) + 1).ToString()) + "
";

Panel1.Controls.Add(link);
}

Panel1.DataBind();
}
}


private void BindData()
{
string connectionString = @"Server=CB-36A\SQLEXPRESS;Database=master;Trusted_Connection=true";
SqlConnection myConnection = new SqlConnection(connectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT ProductName FROM Product", myConnection);

DataSet ds = new DataSet();
ad.Fill(ds);

gvProducts.DataSource = ds;
gvProducts.DataBind();
}

protected void Search(object sender, EventArgs e)
{
// clear the old results
Panel1.Controls.Clear();
Panel1.DataBind();

searchWord = txtSearchBox.Text;
SearchContainer(searchWord);

// Hmmm
BindData();

}

protected string SearchKeyWord(string searchString, string text)
{
Regex reg = new Regex(searchString.Replace(" ", "|"), RegexOptions.IgnoreCase);
return reg.Replace(text,new MatchEvaluator(ReplaceKeyWords));

}

private void SearchContainer(string searchString)
{
int index = 0;

// get the container
DataSet ds = GetDataSet();


double pageIndex = 0;

Regex reg = new Regex(searchString.Replace(" ","|"),RegexOptions.IgnoreCase);

foreach(DataRow row in ds.Tables[0].Rows)
{
if (reg.IsMatch(row["ProductName"] as String))
{
pageIndex = Math.Ceiling( Convert.ToDouble( index / PAGE_SIZE ));

if (hMatches.ContainsKey(pageIndex))
{
hMatches[pageIndex] = ((int)hMatches[pageIndex]) + 1;
}
else
{
hMatches.Add(pageIndex, 1);
}
}

index++;
}

ViewState["MyHashTable"] = hMatches;

CreateLinks();


}

void link_Command(object sender, CommandEventArgs e)
{
gvProducts.PageIndex = Convert.ToInt32( e.CommandArgument);
searchWord = txtSearchBox.Text;
BindData();
}

private DataSet GetDataSet()
{
string connectionString = @"Server=CB-36A\SQLEXPRESS;Database=master;Trusted_Connection=true";
SqlConnection myConnection = new SqlConnection(connectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT ProductName FROM Product", myConnection);

DataSet ds = new DataSet();

ad.Fill(ds);

return ds;
}

private string ReplaceKeyWords(Match m)
{
return "" + m.Value + "";
}

protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvProducts.PageIndex = e.NewPageIndex;
searchWord = txtSearchBox.Text;
BindData();
}
}

Thursday, November 20, 2008

What is custom control? What is the difference between custom control and user control?

Custom controls are controls that are developed by the developer
or a third party vendor. Custom controls are not provided along with
.NET.

Difference between Custom Controls and User Controls.

1.User Control is a page file with extension .ascx which can only be used within
a single application. But custom controls are assemblies(dll files) that can be
used in multiple applications.

2.User Controls cannot be added to the ToolBox of VS.NET . To use a user Control with in an
aspx page u have to drag the user Control from the solution Explorer to designer page.
But Custom Controls can be added to ToolBox of VS.NET.

3.User Controls can be viewed as a sort of generic controls during the design time.
The proper GUI of user controls can be viewed only during the run time.
But Custom Controls can be viewed during the design time.

4. User controls are created from existing Webserver and html server controls .
But a developer who creates custom controls have to render every thing from the scratch.

5.Since the dll assembly of a custom control is being used,a custom control developed in C# can be used in a project developed in VB.NET or any other managed code and vice versa.

User Controls:

1.Have an ascx extension.
2.Are compiled at runtime when the page is loaded.
3.Visual design is possible, just like an aspx page and uses the ASP.Net page model with code behind file.
4.Can only be used on a host aspx page or another user control.
5.Cannot be added to the ToolBox.
6.Can only be used in the current web application (source must be copied to another application to use).

Custom Server Control:

1.Exist in precompiled assemblies.
2.Code entirely contained in .cs (or .vb)
3.No visual designer. Any HTML code needs to be declared programmatically.
4.Can be used in .aspx pages, user controls or other custom server controls.
5.Can be added to the ToolBox (drag and drop)
6.Can be shared between web applications.

Monday, November 10, 2008

Change GridView RowColor OnMouseClick

Introduction:
In this article I will demonstrate that how you can change the color of the GridView row by using simple mouse click and change it back to its original color by clicking the row twice.
The Row Created Event of the GridView:
Like my last article "Changing GridView Row Color OnMouseOver" I used the same approach in populating the GridView. The difference lies in the RowCreated event of the GridView control. Take a look at the RowCreated event below to have a better idea:

protected void MyGridView_RowCreated(object sender, GridViewRowEventArgs e)
{

string rowID = String.Empty;

if (e.Row.RowType == DataControlRowType.DataRow)

{

rowID = "row"+e.Row.RowIndex;

e.Row.Attributes.Add("id","row"+e.Row.RowIndex);

e.Row.Attributes.Add("onclick","ChangeRowColor(" +"'" + rowID + "'" + ")");

}

}

As, you can see in the method above I am assigning different ids to the rows by embedding the id attribute. This will help me distinguish one row from the other. Later, on the onclick attribute I attach the Java Script function "ChangeRowColor" which is responsible for changing the color of the GridView row. The ChangeRowColor function takes in the id of the row. Let's take a look at the ChangeRowColor function.

script language ="javascript" type="text/javascript"
document.body.style.cursor = 'pointer';

var oldColor = '';
function ChangeRowColor(rowID)
{
var color = document.getElementById(rowID).style.backgroundColor;
if(color != 'yellow')
oldColor = color;
if(color == 'yellow')
document.getElementById(rowID).style.backgroundColor = oldColor;
else document.getElementById(rowID).style.backgroundColor = 'yellow';
}

/script

The ChangeRowColor function takes in the id of the row and finds the color of the row. Then it checks that if the color is 'yellow' which, is the color of the highlight row. If it is not yellow then it simply assigns the color to the public variable oldColor which is used to save the previous color of the GridView row. If the color is yellow then we get the previous color and assign to the row so that it can come back to its original state.

Searching Inside the GridView Control And Highlight


There was a post on ASP.NET forums where the user asked how to search inside the GridView control. I was managed to implement this feature although if you plan to use the following code then I would highly recommend that you refactor it as it lacks in performance. In my opinion since you are searching inside the GridView the whole procedure should be handled on the client side using JavaScript or VBScript. Anyhow the following code uses the server side button click event to parse the GridView and highlight the search fields.
protected void Button1_Click(object sender, EventArgs e)
{
string searchString = txtSearch.Text;
StringBuilder sb = new StringBuilder();
DataTable dt = new DataTable();
List rows = new List();
foreach (GridViewRow row in GridView1.Rows)
{
TableCellCollection cells = row.Cells;
foreach (TableCell cell in cells)
{
if (cell.Text.ToLower().StartsWith(searchString.ToLower()))
{
cell.BackColor = System.Drawing.Color.Yellow;
foreach (TableCell c in cells)
{
sb.Append(c.Text);
}
sb.Append("
");
}
else
{
cell.BackColor = System.Drawing.Color.White;
}
}
}
}
The code above simply goes through the GridView row by row and cell by cell. And if it finds a string that starts with the searchString then it highlights it and append it in the StringBuilder object.