Tuesday 29 January 2013

Logical Interview Questions Using C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Program obj = new Program();
            obj.swap(); Console.WriteLine();

            obj.Factorial(); Console.WriteLine();

            obj.Fabbonic(10); Console.WriteLine();

            obj.TriUpToDown(); Console.WriteLine();

            obj.TriDownToUp(); Console.WriteLine();

            obj.InterchageNebhorVaules(); Console.WriteLine();

            obj.InterchageFirstToLastSoOn(); Console.WriteLine();

            obj.xMasTree(); Console.WriteLine();

            obj.LeapYear(2016); Console.WriteLine();

            Console.ReadLine();
        }

        protected void swap()
        {
            int a = 5, b = 6;
            Console.WriteLine(a.ToString() + "  " + b.ToString());
            b = a + b;
            a = b - a;
            b = b - a;
            Console.WriteLine(a.ToString() + "  " + b.ToString());
        }

        protected void Factorial()
        {
            int a = 7;
            int c = 1;
            for (int i = 1; i <= a; i++)
            {
                c = c * i;
            }
            Console.WriteLine(c.ToString());
        }

        protected void Fabbonic(int till)
        {
            int a = 1, b = 1;
            int c;
            Console.Write(a.ToString() + " " + b.ToString() + " ");
            for (int i = 1; i < till; i++)
            {
                c = a + b;
                a = b;
                b = c;
                Console.Write(c.ToString() + " ");
            }
        }

        protected void TriUpToDown()
        {
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }

        protected void TriDownToUp()
        {
            for (int i = 0; i < 6; i++)
            {
                for (int j = i; j < 6; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }

        protected void xMasTree()
        {
            int a = 0;
            for (int i = 0; i < 8; i++)
            {
                for (int k = i; k < 8; k++)
                {
                    Console.Write(" ");
                }
                for (int j = 0; j < i; j++)
                {
                    Console.Write("* ");
                }
                Console.WriteLine();
                a++;
                if (a == 3 || a == 7)
                    i = 1;
            }
        }

        protected void InterchageNebhorVaules()
        {
            string input = "NITISH";
            Char[] arrInput = input.ToCharArray();

            StringBuilder output = new StringBuilder();
            for (int i = 0; i < arrInput.Length / 2; i++)
            {
                output.Append(arrInput[i + 1].ToString());
                output.Append(arrInput[i].ToString());
            }

            Console.WriteLine(input + " >>  " + output.ToString());
        }

        protected void InterchageFirstToLastSoOn()
        {
            string input1 = "NITISH";
            StringBuilder output1 = new StringBuilder();
            StringBuilder output2 = new StringBuilder();

            char[] characters1 = input1.ToCharArray();

            for (int i = 0; i < characters1.Length / 2; i++)
            {
                output1.Append(characters1[characters1.Length - (i + 1)]);
                output2.Append(characters1[i]);
            }
            Console.Write(input1.ToString() + " >--> " + output1.ToString() + Operation.ReverseString(output2.ToString()));
        }

        protected void LeapYear(int yr)
        {            
            if ((yr % 4 == 0 && yr % 100 != 0) || (yr % 400 == 0))
            {
                Console.WriteLine(yr.ToString() + " is a leap year.");
            }
            else
            {
                Console.WriteLine(yr.ToString() + " is not a leap year.");
            }
            Console.Read();
        }
    }

    static class Operation
    {
        /// <summary>
        /// Receives string and returns the string with its letters reversed.
        /// </summary>
        public static string ReverseString(string s)
        {
            char[] arr = s.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
        }
    }
}

Friday 18 January 2013

Dynamic GridView in ASP.NET Using C#

....................................................................

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamciGridView.aspx.cs" Inherits="DynamciGridView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 55px"><table align="center" ><tr><td>
    <asp:PlaceHolder ID="PlaceHolder1" runat="server" />
    </td></tr>
    <tr><td><center ><asp:Button ID="btnSaveGrid" runat="server" Text="Save"
            Visible="false" BackColor="#006666" BorderColor="#CC00CC" Font-Bold="True"
            Font-Italic="True" Font-Size="Medium" ForeColor="#FF33CC" Height="26px"
            onclick="btnSaveGrid_Click" Width="51px" /></center>
    </td></tr></table>
    </div>
    </form>
</body>
</html>


...........................................................................................................................

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;




public partial class DynamciGridView : System.Web.UI.Page
{
    GridView gvDynamic = new GridView();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FirstGridViewRow();
            gvDynamic.AutoGenerateColumns = false;
            gvDynamic.HeaderStyle.BackColor = System.Drawing.Color.DarkTurquoise;
            gvDynamic.RowStyle.BackColor = System.Drawing.Color.DarkMagenta;
            gvDynamic.AlternatingRowStyle.BackColor = System.Drawing.Color.DarkSalmon;
        }
    }

    private void FirstGridViewRow()
    {
        DataTable dt = new DataTable();
        TextBox txtname = new TextBox();
        DataRow dr = null;
        DataRow dr2 = null;
        dr = dt.NewRow();
        dr2 = dt.NewRow();

        dt.Rows.Add(dr);
        dt.Rows.Add(dr2);

        TemplateField tfObject = new TemplateField();
        tfObject.HeaderText = "Name";
        //tfObject.HeaderStyle.Width = Unit.Percentage(30);
        tfObject.ItemTemplate = new CreateItemTemplate(ListItemType.Item);
        gvDynamic.Columns .Add (tfObject);

        //TemplateField tfObject2 = new TemplateField();
        //tfObject2.HeaderText = "City";
        ////tfObject2.HeaderStyle.Width = Unit.Percentage(30);
        //tfObject2.ItemTemplate = new CreateItemTemplate(ListItemType.Item);
        //gvDynamic.Columns.Add(tfObject2);

        //TemplateField tfObject3 = new TemplateField();
        //tfObject3.HeaderText = "Cont. No.";
        ////tfObject2.HeaderStyle.Width = Unit.Percentage(30);
        //tfObject3.ItemTemplate = new CreateItemTemplate(ListItemType.Item);
        //gvDynamic.Columns.Add(tfObject3);

        tfObject = new TemplateField();
        tfObject.HeaderText = "City";
        tfObject.ItemTemplate = new CreateItemTemplate(ListItemType.Item);
        gvDynamic.Columns.Add(tfObject);

        tfObject = new TemplateField();
        tfObject.HeaderText = "Cont. No.";
        tfObject.ItemTemplate = new CreateItemTemplate(ListItemType.Item);
        gvDynamic.Columns.Add(tfObject);
        //tfObject.HeaderTemplate = new CreateItemTemplate(ListItemType.Header);
        //tfObject.FooterTemplate = new CreateItemTemplate(ListItemType.Footer);


        ViewState["CurrentTable"] = dt;

        gvDynamic.DataSource = dt;
        gvDynamic.DataBind();
        PlaceHolder1.Controls.Add(gvDynamic);
        btnSaveGrid.Visible = true;
    }

    protected void btnSaveGrid_Click(object sender, EventArgs e)
    {
    }

public class CreateItemTemplate : ITemplate
{

    //Field to store the ListItemType value
    private ListItemType myListItemType;

    public CreateItemTemplate()
    {
        //
        // TODO: Add default constructor logic here
        //
    }

    //Parameterrised constructor
    public CreateItemTemplate(ListItemType Item)
    {
        myListItemType = Item;
    }


    //Overwrite the InstantiateIn() function of the ITemplate interface.
    public void InstantiateIn(System.Web.UI.Control container)
    {
        //Code to create the ItemTemplate and its field.
        if (myListItemType == ListItemType.Item)
        {
            TextBox txtCashCheque = new TextBox();
            txtCashCheque.ID = "txtDynamic";
            container.Controls.Add(txtCashCheque);
        }

        //Code to create the HeaderTemplate and its field.
        if (myListItemType == ListItemType.Header)
        {
            Label lblTest = new Label();
            lblTest.Text = "Header Text";
            container.Controls.Add(lblTest);

        }

        //Code to create the FooterTemplate and its field.
        if (myListItemType == ListItemType.Footer)
        {
            Label lblTest = new Label();
            lblTest.Text = "";
            container.Controls.Add(lblTest);
        }

    }

}

Just Paste This Code.

All The Best!!!

How To Create Appendable GridView In ASP.NET Using C#.

1. Create Table
Create Table TBL_AppendGrid
(
Stu_ID Int identity,
Stu_Name varchar(50),
Stu_Location varchar(50),
Stu_ContactNo varchar(20)
)

2. Create Procedure

CREATE procedure PR_InsertTo_AppendGrid

@Name varchar(30), 
@Location varchar(50), 
@Mobile varchar(11) 

 
as 
begin 
 if not exists(select Stu_Name, Stu_Location, Stu_ContactNo from TBL_AppendGrid where Stu_Name=@Name and Stu_Location=@Location and Stu_ContactNo=@Mobile) 
 begin 
  insert into  TBL_AppendGrid(Stu_Name, Stu_Location, Stu_ContactNo) values(@Name, @Location, @Mobile) 
  select '1' 
 end 
 else 
 begin 
  update TBL_AppendGrid set Stu_Name=@Name, Stu_Location=@location, Stu_ContactNo=@Mobile where Stu_Name=@Name and Stu_Location=@Location and Stu_ContactNo=@Mobile
  select '0' 
 end 
end


3. <appSettings>
  <add key="ConnectionString" value="Server=Your_Server; Database=Your_Data; uid=sa; pwd=saa;" />
</appSettings>


4. Open Visual Studio 2008 or else..

and paste this code

................................................................................................................................
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AppendableGridView.aspx.cs" Inherits="AppendableGridView" EnableEventValidation ="false"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <table align="center" > 
    <tr><td><center ><b><asp:Label ID="lblres" runat="server" /></b></center>
       
        </td></tr>
    <tr><td>
    <asp:UpdatePanel ID ="UpdatePanel1" runat ="server" >
    <ContentTemplate >
    <asp:GridView ID="AppendGrid" runat="server" AutoGenerateColumns="False"
            BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
            CellPadding="4" GridLines="Horizontal" Height="141px"
            OnRowCommand ="AppendGrid_RowCommand" >
           

        <RowStyle BackColor="White" ForeColor="#333333" />
    <Columns>
    <asp:BoundField DataField="RowNumber" HeaderText="SNo" />
    <asp:TemplateField HeaderText="Name">
    <ItemTemplate >
    <asp:TextBox ID="txtIName" runat="server" />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtIName"
                                ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
    </ItemTemplate>
    </asp:TemplateField>
   
    <asp:TemplateField HeaderText="Location">
    <ItemTemplate >
    <asp:TextBox ID="txtIlocation" runat="server" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtIlocation"
                                ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
    </ItemTemplate>
    </asp:TemplateField>
   
    <asp:TemplateField HeaderText="Contact No">
    <ItemTemplate >
    <asp:TextBox ID="txtIMob" runat="server"  />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtIMob"
                                ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
        <FooterStyle BackColor="White" ForeColor="#333333" />
        <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#FFFFCC" />
    </asp:GridView></ContentTemplate></asp:UpdatePanel>
    </td></tr>
    <tr><td><center ><asp:Button ID="hidden"  Text="Append Row" runat ="server" Visible="true"
            onclick="hidden_Click"   />
    <asp:Button ID="btnSave" runat ="server" Text="Save" onclick="btnSave_Click" />
   
        </center></td></tr>
    </table>
    </div>
    </form>
</body>
</html>

5.  Code Behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;


public partial class AppendableGridView : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

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

    private void FirstGridViewRow()
    {
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Col1", typeof(string)));
        dt.Columns.Add(new DataColumn("Col2", typeof(string)));
        dt.Columns.Add(new DataColumn("Col3", typeof(string)));

        dr = dt.NewRow();
        dr["RowNumber"] = 1;
        dr["Col1"] = string.Empty;
        dr["Col2"] = string.Empty;
        dr["Col3"] = string.Empty;

        dt.Rows.Add(dr);

        ViewState["CurrentTable"] = dt;

        AppendGrid.DataSource = dt;
        AppendGrid.DataBind();
    }

    private void appendNewRow()
    {
        int rowIndex = 0;
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow drCurrentRow = null;
            if (dtCurrentTable.Rows.Count > 0)
            {
                for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                {
                    TextBox txtName = (TextBox)AppendGrid.Rows[rowIndex].Cells[1].FindControl("txtIName");
                    TextBox txtLocation = (TextBox)AppendGrid.Rows[rowIndex].Cells[2].FindControl("txtIlocation");
                    TextBox txtMob = (TextBox)AppendGrid.Rows[rowIndex].Cells[3].FindControl("txtIMob");
                    drCurrentRow = dtCurrentTable.NewRow();
                    drCurrentRow["RowNumber"] = i + 1;

                    dtCurrentTable.Rows[i - 1]["Col1"] = txtName.Text;
                    dtCurrentTable.Rows[i - 1]["Col2"] = txtLocation.Text;
                    dtCurrentTable.Rows[i - 1]["Col3"] = txtMob.Text;
                    rowIndex++;
                }
                dtCurrentTable.Rows.Add(drCurrentRow);
                ViewState["CurrentTable"] = dtCurrentTable;

                AppendGrid.DataSource = dtCurrentTable;
                AppendGrid.DataBind();

                TextBox txn = (TextBox)AppendGrid.Rows[AppendGrid .Rows .Count-1 ].Cells[1].FindControl("txtIName");
                txn.Focus();
                // Focus on last row.
            }
        }
        else
        {
            Response.Write("ViewState Null Hai");
        }
        storeExistingValue();
    }


    private void storeExistingValue()
    {
        int rowIndex = 0;
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dt = (DataTable)ViewState["CurrentTable"];
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TextBox txtName = (TextBox)AppendGrid.Rows[rowIndex].Cells[1].FindControl("txtIName");
                    TextBox txtLocation = (TextBox)AppendGrid.Rows[rowIndex].Cells[2].FindControl("txtIlocation");
                    TextBox txtMob = (TextBox)AppendGrid.Rows[rowIndex].Cells[3].FindControl("txtIMob");

                    txtName.Text = dt.Rows[i]["Col1"].ToString();
                    txtLocation.Text = dt.Rows[i]["Col2"].ToString();
                    txtMob.Text = dt.Rows[i]["Col3"].ToString();
                    rowIndex++;
                }
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
         foreach (GridViewRow row in this.AppendGrid .Rows )
         {
           
              try
               {
                    TextBox txtName = (TextBox)row.FindControl("txtIName");
                    TextBox txtLocation = (TextBox)row.FindControl("txtIlocation");
                    TextBox txtMob = (TextBox)row.FindControl("txtIMob");

                     con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                    SqlCommand cmd = new SqlCommand("PR_InsertTo_AppendGrid", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Name", txtName.Text.ToString());
                    cmd.Parameters.AddWithValue("@Location", txtLocation.Text.ToString());
                    cmd.Parameters.AddWithValue("Mobile", txtMob.Text.ToString());
                    con.Open();

                    int res = cmd.ExecuteNonQuery();
                    if (res.Equals("1"))
                    {
                        lblres.Text = "Saved";
                    }
                    else
                    { lblres.Text = "Updated"; }
                }
                catch (Exception ex)
                {
                        lblres.Text = ex.Message;
                }

              finally
              {
                  con.Close();
                  con.Dispose();
              }
          }
         ViewState["CurrentTable"] = null;
         Page.Response.Redirect(Request.Url.ToString());
    }

    protected void AppendGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
     
    }

    protected void hidden_Click(object sender, EventArgs e)
    {
        appendNewRow();
    }
}


All The Best!!!

Thursday 17 January 2013

Difference Among SQL Server 2005, 2008 & 2012



SQL Server 2005

SQL Server 2005 (formerly codenamed "Yukon") was released in October 2005. It included native support for managing XML data, in addition to relational data. For this purpose, it defined an xml data type that could be used either as a data type in database columns or as literals in queries. XML columns can be associated with XSD schemas; XML data being stored is verified against the schema. XML is converted to an internal binary data type before being stored in the database. Specialized indexing methods were made available for XML data. XML data is queried using XQuery; SQL Server 2005 added some extensions to the T-SQL language to allow embedding XQuery queries in T-SQL. In addition, it also defines a new extension to XQuery, called XML DML, that allows query-based modifications to XML data. SQL Server 2005 also allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests. When the data is accessed over web services, results are returned as XML.

Common Language Runtime (CLR) integration was introduced with this version, enabling one to write SQL code as Managed Code by the CLR. For relational data, T-SQL has been augmented with error handling features (try/catch) and support for recursive queries with CTEs (Common Table Expressions). SQL Server 2005 has also been enhanced with new indexing algorithms, syntax and better error recovery systems. Data pages are checksummed for better error resiliency, and optimistic concurrency support has been added for better performance. Permissions and access control have been made more granular and the query processor handles concurrent execution of queries in a more efficient way. Partitions on tables and indexes are supported natively, so scaling out a database onto a cluster is easier. SQL CLR was introduced with SQL Server 2005 to let it integrate with the .NET Framework.

SQL Server 2005 introduced "MARS" (Multiple Active Results Sets), a method of allowing usage of database connections for multiple purposes.

SQL Server 2005 introduced DMVs (Dynamic Management Views), which are specialized views and functions that return server state information that can be used to monitor the health of a server instance, diagnose problems, and tune performance.

Service Pack 1 (SP1) of SQL Server 2005 introduced Database Mirroring, a high availability option that provides redundancy and failover capabilities at the database level. Failover can be performed manually or can be configured for automatic failover. Automatic failover requires a witness partner and an operating mode of synchronous (also known as high-safety or full safety).


SQL Server 2008

SQL Server 2008 (formerly codenamed "Katmai") was released on August 6, 2008 and aims to make data management self-tuning, self organizing, and self maintaining with the development of SQL Server Always On technologies, to provide near-zero downtime. SQL Server 2008 also includes support for structured and semi-structured data, including digital media formats for pictures, audio, video and other multimedia data. In current versions, such multimedia data can be stored as BLOBs (binary large objects), but they are generic bitstreams. Intrinsic awareness of multimedia data will allow specialized functions to be performed on them. According to Paul Flessner, senior Vice President, Server Applications, Microsoft Corp., SQL Server 2008 can be a data storage backend for different varieties of data: XML, email, time/calendar, file, document, spatial, etc as well as perform search, query, analysis, sharing, and synchronization across all data types.

Other new data types include specialized date and time types and a Spatial data type for location-dependent data. Better support for unstructured and semi-structured data is provided using the new FILESTREAM[15] data type, which can be used to reference any file stored on the file system. Structured data and metadata about the file is stored in SQL Server database, whereas the unstructured component is stored in the file system. Such files can be accessed both via Win32 file handling APIs as well as via SQL Server using T-SQL; doing the latter accesses the file data as a BLOB. Backing up and restoring the database backs up or restores the referenced files as well. SQL Server 2008 also natively supports hierarchical data, and includes T-SQL constructs to directly deal with them, without using recursive queries.

The Full-text search functionality has been integrated with the database engine. According to a Microsoft technical article, this simplifies management and improves performance.

Spatial data will be stored in two types. A "Flat Earth" (GEOMETRY or planar) data type represents geospatial data which has been projected from its native, spherical, coordinate system into a plane. A "Round Earth" data type (GEOGRAPHY) uses an ellipsoidal model in which the Earth is defined as a single continuous entity which does not suffer from the singularities such as the international dateline, poles, or map projection zone "edges". Approximately 70 methods are available to represent spatial operations for the Open Geospatial Consortium Simple Features for SQL, Version 1.1.

SQL Server includes better compression features, which also helps in improving scalability. It enhanced the indexing algorithms and introduced the notion of filtered indexes. It also includes Resource Governor that allows reserving resources for certain users or workflows. It also includes capabilities for transparent encryption of data (TDE) as well as compression of backups. SQL Server 2008 supports the ADO.NET Entity Framework and the reporting tools, replication, and data definition will be built around the Entity Data Model. SQL Server Reporting Services will gain charting capabilities from the integration of the data visualization products from Dundas Data Visualization, Inc., which was acquired by Microsoft. On the management side, SQL Server 2008 includes the Declarative Management Framework which allows configuring policies and constraints, on the entire database or certain tables, declaratively. The version of SQL Server Management Studio included with SQL Server 2008 supports IntelliSense for SQL queries against a SQL Server 2008 Database Engine. SQL Server 2008 also makes the databases available via Windows PowerShell providers and management functionality available as Cmdlets, so that the server and all the running instances can be managed from Windows PowerShell.


SQL Server 2008 R2

SQL Server 2008 R2 (10.50.1600.1, formerly codenamed "Kilimanjaro") was announced at TechEd 2009, and was released to manufacturing on April 21, 2010. SQL Server 2008 R2 adds certain features to SQL Server 2008 including a master data management system branded as Master Data Services, a central management of master data entities and hierarchies. Also Multi Server Management, a centralized console to manage multiple SQL Server 2008 instances and services including relational databases, Reporting Services, Analysis Services & Integration Services.

SQL Server 2008 R2 includes a number of new services, including PowerPivot for Excel and SharePoint, Master Data Services, StreamInsight, Report Builder 3.0, Reporting Services Add-in for SharePoint, a Data-tier function in Visual Studio that enables packaging of tiered databases as part of an application, and a SQL Server Utility named UC (Utility Control Point), part of AMSM (Application and Multi-Server Management) that is used to manage multiple SQL Servers.

The first SQL Server 2008 R2 service pack (10.50.2500, Service Pack 1) was released on July 11, 2011.

The second SQL Server 2008 R2 service pack (10.50.4000, Service Pack 2) was released on July 26, 2012.


SQL Server 2012

At the 2011 Professional Association for SQL Server (PASS) summit on October 11, Microsoft announced that the next major version of SQL Server (codenamed "Denali"), would be SQL Server 2012. It was released to manufacturing on March 6, 2012.

It was announced to be the last version to natively support OLE DB and instead to prefer ODBC for native connectivity.

SQL Server 2012's new features and enhancements include AlwaysOn SQL Server Failover Cluster Instances and Availability Groups which provides a set of options to improve database availability, Contained Databases which simplify the moving of databases between instances, new and modified Dynamic Management Views and Functions, programmability enhancements including new spatial features, metadata discovery, sequence objects and the THROW statement, performance enhancements such as ColumnStore Indexes as well as improvements to OnLine and partition level operations  and security enhancements including provisioning during setup, new permissions, improved role management and default schema assignment for groups.










In Short:
SQL SERVER 2005
·         It included native support for managing XML data, in addition to relational data. For this purpose, it defined an xml data type that could be used either as a data type in database columns or as literals in queries.

·         SQL Server 2005 added some extensions to the T-SQL language to allow embedding XQuery queries in T-SQL. In addition, it also defines a new extension to XQuery, called XML DML, that allows query-based modifications to XML data.

·         SQL Server 2005 introduced "MARS" (Multiple Active Results Sets), a method of allowing usage of database connections for multiple purposes.

·         SQL Server 2005 introduced DMVs (Dynamic Management Views), which are specialized views and functions that return server state information that can be used to monitor the health of a server instance, diagnose problems, and tune performance.


SQL SERVER 2008

·         It aims to make data management self-tuning, self organizing, and self maintaining with the development of SQL Server Always On technologies, to provide near-zero downtime.

·         SQL Server 2008 also includes support for structured and semi-structured data, including digital media formats for pictures, audio, video and other multimedia data.

·         SQL Server 2008 can be a data storage backend for different varieties of data: XML, email, time/calendar, file, document, spatial, etc as well as perform search, query, analysis, sharing, and synchronization across all data types.

·         The Full-text search functionality has been integrated with the database engine. According to a Microsoft technical article, this simplifies management and improves performance.


SQL SERVER 2012

·         It was announced to be the last version to natively support OLE DB and instead to prefer ODBC for native connectivity.

·         It includes AlwaysOn SQL Server Failover Cluster Instances and Availability Groups which provides a set of options to improve database availability, Contained Databases which simplify the moving of databases between instances, new and modified Dynamic Management Views and Functions, programmability enhancements including new spatial features, metadata discovery, sequence objects and the THROW statement, performance enhancements such as ColumnStore Indexes as well as improvements to OnLine and partition level operations  and security enhancements including provisioning during setup, new permissions, improved role management and default schema assignment for groups.





Transact-SQL (T-SQL) is Microsoft's and Sybase's proprietary extension to SQL. SQL, often expanded to Structured Query Language, is a standardized computer language that was originally developed by IBM for querying, altering and defining relational databases, using declarative statements. T-SQL expands on the SQL standard to include procedural programming, local variables, various support functions for string processing, data processing, mathematics, etc. and changes to the DELETE and UPDATE statements. These additional features make Transact-SQL Turing complete.
Transact-SQL is central to using Microsoft SQL Server. All applications that communicate with an instance of SQL Server do so by sending Transact-SQL statements to the server, regardless of the user interface of the application.


All The Best!!!

Friday 4 January 2013

Download GridView As PDF, Excel, Word Format.

Hello Dudes! Lets have the Idea about Downloading GridView As PDF Format.

1. Create A Table As

Create Table Tbl_Dtl
(
S_ID int,
S_Name varchar(50),
S_Mob varchar(20)
)

2. Now Come To Visual Studio 2005/2008 or what have you else,

 File -> New ->Website -> Name ("GridView_PDF"). OK

3. Code GridView_PDF.aspx As

**********************************************************



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView_PDF.cs" Inherits="GridView_PDF" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>GridView To PDF</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <center>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Font-Names="Arial"
                Font-Size="11pt" AllowPaging="true">
                <Columns>
                    <asp:BoundField ItemStyle-Width="150px" DataField="S_ID" HeaderText="ID" />
                    <asp:BoundField ItemStyle-Width="150px" DataField="S_Name" HeaderText="Name" />
                    <asp:BoundField ItemStyle-Width="150px" DataField="S_Mob" HeaderText="Contact No." />
                </Columns>
            </asp:GridView>
            <br />
            <asp:Button ID="btnExportWord" runat="server" Text="ExportToWord" OnClick="btnExportWord_Click" />

            <asp:Button ID="btnExportExcel" runat="server" Text="ExportToExcel" OnClick="btnExportExcel_Click" />

            <asp:Button ID="btnExportPDF" runat="server" Text="ExportToPDF" OnClick="btnExportPDF_Click" />
        </center>
    </div>
    </form>
</body>
</html>

******************************************************************

4. Now Go To This Link http://www.nodevice.com/dll/itextsharp_dll/item21198.html

and Download itextsharp.dll

5. Now Open Solution Explorer (Ctrl+W,S) and Right Click On Your File Path and Click Add Reference -> Browse and add itextsharp.dll  & Ok

7. Now GridView_PDF.cs As

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.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Text;

public partial class CSharp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strQuery = "select * from Tbl_Dtl";
        SqlCommand cmd = new SqlCommand(strQuery);
        DataTable dt = GetData(cmd);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    private DataTable GetData(SqlCommand cmd)
    {
        DataTable dt = new DataTable();
        String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConnString);
        SqlDataAdapter sda = new SqlDataAdapter();
        cmd.CommandType = CommandType.Text;
        cmd.Connection = con;
        try
        {
            con.Open();
            sda.SelectCommand = cmd;
            sda.Fill(dt);
            return dt;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            con.Close();
            sda.Dispose();
            con.Dispose();
        }
    }
  

    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }

    protected void btnExportWord_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.doc");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-word ";
        StringWriter sw= new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.RenderControl(hw);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
    }

    protected void btnExportExcel_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
      
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GridView1.AllowPaging = false;
        GridView1.DataBind();

        //Change the Header Row back to white color
        GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");

        //Apply style to Individual Cells
        GridView1.HeaderRow.Cells[0].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[1].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[2].Style.Add("background-color", "green");
        

        for (int i = 0; i < GridView1.Rows.Count;i++ )
        {
            GridViewRow row = GridView1.Rows[i];
           
            //Change Color back to white
            row.BackColor = System.Drawing.Color.White;

            //Apply text style to each Row
            row.Attributes.Add("class", "textmode");

            //Apply style to Individual Cells of Alternating Row
            if (i % 2 != 0)
            {
                row.Cells[0].Style.Add("background-color", "#C2D69B");
                row.Cells[1].Style.Add("background-color", "#C2D69B");
                row.Cells[2].Style.Add("background-color", "#C2D69B");
                           

        }

        GridView1.RenderControl(hw);
        string style = @"<style> .textmode { mso-number-format:\@; } </style>";
        Response.Write(style);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
    }

    protected void btnExportPDF_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f,10f,10f,0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End(); 
    }
  
}
 



Now Run Your Page

All Done!!

All The Best!!!