Wednesday, November 29, 2017

SQL server - Generate DDL of Tables


Recently I had bad time while generating DDL (Data Definition Language ) of a table from SQL Server database (having more than 1 M tables ) . It took a while to generate DDL script using "Script Table As" --> Create To --> "New Query Editor Window" .

I found another alternative to generate DDL Sql , with help of a simple SQL script . which can be useful to run against bad performing DB's on DDL generation utility .



DECLARE @table_name SYSNAME
SELECT @table_name = 'dbo.{Your table name goes here}'

DECLARE
      @object_name SYSNAME
    , @object_id INT

SELECT
      @object_name = '[' + s.name + '].[' + o.name + ']'
    , @object_id = o.[object_id]
FROM sys.objects o WITH (NOWAIT)
JOIN sys.schemas s WITH (NOWAIT) ON o.[schema_id] = s.[schema_id]
WHERE s.name + '.' + o.name = @table_name
    AND o.[type] = 'U'
    AND o.is_ms_shipped = 0

DECLARE @SQL nvarchar;

;WITH index_column AS
(
    SELECT
          ic.[object_id]
        , ic.index_id
        , ic.is_descending_key
        , ic.is_included_column
        , c.name
    FROM sys.index_columns ic WITH (NOWAIT)
    JOIN sys.columns c WITH (NOWAIT) ON ic.[object_id] = c.[object_id] AND ic.column_id = c.column_id
    WHERE ic.[object_id] = @object_id
),
fk_columns AS
(
     SELECT
          k.constraint_object_id
        , cname = c.name
        , rcname = rc.name
    FROM sys.foreign_key_columns k WITH (NOWAIT)
    JOIN sys.columns rc WITH (NOWAIT) ON rc.[object_id] = k.referenced_object_id AND rc.column_id = k.referenced_column_id
    JOIN sys.columns c WITH (NOWAIT) ON c.[object_id] = k.parent_object_id AND c.column_id = k.parent_column_id
    WHERE k.parent_object_id = @object_id
)
SELECT @SQL = 'CREATE TABLE ' + @object_name + CHAR(13) + '(' + CHAR(13) + STUFF((
    SELECT CHAR(9) + ', [' + c.name + '] ' +
        CASE WHEN c.is_computed = 1
            THEN 'AS ' + cc.[definition]
            ELSE UPPER(tp.name) +
                CASE WHEN tp.name IN ('varchar', 'char', 'varbinary', 'binary', 'text')
                       THEN '(' + CASE WHEN c.max_length = -1 THEN 'MAX' ELSE CAST(c.max_length AS VARCHAR(5)) END + ')'
                     WHEN tp.name IN ('nvarchar', 'nchar', 'ntext')
                       THEN '(' + CASE WHEN c.max_length = -1 THEN 'MAX' ELSE CAST(c.max_length / 2 AS VARCHAR(5)) END + ')'
                     WHEN tp.name IN ('datetime2', 'time2', 'datetimeoffset')
                       THEN '(' + CAST(c.scale AS VARCHAR(5)) + ')'
                     WHEN tp.name = 'decimal'
                       THEN '(' + CAST(c.[precision] AS VARCHAR(5)) + ',' + CAST(c.scale AS VARCHAR(5)) + ')'
                    ELSE ''
                END +
                CASE WHEN c.collation_name IS NOT NULL THEN ' COLLATE ' + c.collation_name ELSE '' END +
                CASE WHEN c.is_nullable = 1 THEN ' NULL' ELSE ' NOT NULL' END +
                CASE WHEN dc.[definition] IS NOT NULL THEN ' DEFAULT' + dc.[definition] ELSE '' END +
                CASE WHEN ic.is_identity = 1 THEN ' IDENTITY(' + CAST(ISNULL(ic.seed_value, '0') AS CHAR(1)) + ',' + CAST(ISNULL(ic.increment_value, '1') AS CHAR(1)) + ')' ELSE '' END
        END + CHAR(13)
    FROM sys.columns c WITH (NOWAIT)
    JOIN sys.types tp WITH (NOWAIT) ON c.user_type_id = tp.user_type_id
    LEFT JOIN sys.computed_columns cc WITH (NOWAIT) ON c.[object_id] = cc.[object_id] AND c.column_id = cc.column_id
    LEFT JOIN sys.default_constraints dc WITH (NOWAIT) ON c.default_object_id != 0 AND c.[object_id] = dc.parent_object_id AND c.column_id = dc.parent_column_id
    LEFT JOIN sys.identity_columns ic WITH (NOWAIT) ON c.is_identity = 1 AND c.[object_id] = ic.[object_id] AND c.column_id = ic.column_id
    WHERE c.[object_id] = @object_id
    ORDER BY c.column_id
    FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, CHAR(9) + ' ')
    + ISNULL((SELECT CHAR(9) + ', CONSTRAINT [' + k.name + '] PRIMARY KEY (' +
                    (SELECT STUFF((
                         SELECT ', [' + c.name + '] ' + CASE WHEN ic.is_descending_key = 1 THEN 'DESC' ELSE 'ASC' END
                         FROM sys.index_columns ic WITH (NOWAIT)
                         JOIN sys.columns c WITH (NOWAIT) ON c.[object_id] = ic.[object_id] AND c.column_id = ic.column_id
                         WHERE ic.is_included_column = 0
                             AND ic.[object_id] = k.parent_object_id
                             AND ic.index_id = k.unique_index_id    
                         FOR XML PATH(N''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, ''))
            + ')' + CHAR(13)
            FROM sys.key_constraints k WITH (NOWAIT)
            WHERE k.parent_object_id = @object_id
                AND k.[type] = 'PK'), '') + ')'  + CHAR(13)
    + ISNULL((SELECT (
        SELECT CHAR(13) +
             'ALTER TABLE ' + @object_name + ' WITH'
            + CASE WHEN fk.is_not_trusted = 1
                THEN ' NOCHECK'
                ELSE ' CHECK'
              END +
              ' ADD CONSTRAINT [' + fk.name  + '] FOREIGN KEY('
              + STUFF((
                SELECT ', [' + k.cname + ']'
                FROM fk_columns k
                WHERE k.constraint_object_id = fk.[object_id]
                FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '')
               + ')' +
              ' REFERENCES [' + SCHEMA_NAME(ro.[schema_id]) + '].[' + ro.name + '] ('
              + STUFF((
                SELECT ', [' + k.rcname + ']'
                FROM fk_columns k
                WHERE k.constraint_object_id = fk.[object_id]
                FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '')
               + ')'
            + CASE
                WHEN fk.delete_referential_action = 1 THEN ' ON DELETE CASCADE'
                WHEN fk.delete_referential_action = 2 THEN ' ON DELETE SET NULL'
                WHEN fk.delete_referential_action = 3 THEN ' ON DELETE SET DEFAULT'
                ELSE ''
              END
            + CASE
                WHEN fk.update_referential_action = 1 THEN ' ON UPDATE CASCADE'
                WHEN fk.update_referential_action = 2 THEN ' ON UPDATE SET NULL'
                WHEN fk.update_referential_action = 3 THEN ' ON UPDATE SET DEFAULT' 
                ELSE ''
              END
            + CHAR(13) + 'ALTER TABLE ' + @object_name + ' CHECK CONSTRAINT [' + fk.name  + ']' + CHAR(13)
        FROM sys.foreign_keys fk WITH (NOWAIT)
        JOIN sys.objects ro WITH (NOWAIT) ON ro.[object_id] = fk.referenced_object_id
        WHERE fk.parent_object_id = @object_id
        FOR XML PATH(N''), TYPE).value('.', 'NVARCHAR(MAX)')), '')
    + ISNULL(((SELECT
         CHAR(13) + 'CREATE' + CASE WHEN i.is_unique = 1 THEN ' UNIQUE' ELSE '' END
                + ' NONCLUSTERED INDEX [' + i.name + '] ON ' + @object_name + ' (' +
                STUFF((
                SELECT ', [' + c.name + ']' + CASE WHEN c.is_descending_key = 1 THEN ' DESC' ELSE ' ASC' END
                FROM index_column c
                WHERE c.is_included_column = 0
                    AND c.index_id = i.index_id
                FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '') + ')' 
                + ISNULL(CHAR(13) + 'INCLUDE (' +
                    STUFF((
                    SELECT ', [' + c.name + ']'
                    FROM index_column c
                    WHERE c.is_included_column = 1
                        AND c.index_id = i.index_id
                    FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '') + ')', '')  + CHAR(13)
        FROM sys.indexes i WITH (NOWAIT)
        WHERE i.[object_id] = @object_id
            AND i.is_primary_key = 0
            AND i.[type] = 2
        FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)')
    ), '')

select  @SQL;

Friday, May 10, 2013

SQL Deleting duplicate records by keeping a single row


Recently i came across a situation to remove duplicate records from a table by keeping a row . i used below listed SQL query pattern to achieve this .


DELETE
FROM Foo1
WHERE Foo1.ID IN

-- List 1 - all rows that have duplicates
(SELECT F.ID
FROM Foo1 AS F
WHERE Exists (SELECT Field1, Field2, Count(ID)
FROM Foo1
WHERE Foo1.Field1 = F.Field1
   AND Foo1.Field2 = F.Field2
GROUP BY Foo1.Field1, Foo1.Field2
HAVING Count(Foo1.ID) > 1))
AND Foo1.ID NOT IN

-- List 2 - one row from each set of duplicate
(SELECT Min(ID)
FROM Foo1 AS F
WHERE Exists (SELECT Field1, Field2, Count(ID)
FROM Foo1
WHERE Foo1.Field1 = F.Field1
   AND Foo1.Field2 = F.Field2
GROUP BY Foo1.Field1, Foo1.Field2
HAVING Count(Foo1.ID) > 1)
GROUP BY Field1, Field2);

Thursday, November 8, 2012

Free .NET Decompiler and Assembly Browser


I was a great fan of .Net reflector (http://www.reflector.net/) , but that application is purchased by Redgate and started charging licence fees  .

Recently i came across a free .Net decompiler -  dotpeek from jetbrains . it is really cool .. it has almost all features offered by .Net reflector. so its time to switch .


http://www.jetbrains.com/decompiler/


Monday, November 5, 2012

SQL Server - Query to get references & constraints of a table



Just substitute 'YOUR TABLE NAME'  to the name of the table you want to see Reference , Constraints and other relationships.


SELECT
    K_Table = FK.TABLE_NAME,
    FK_Column = CU.COLUMN_NAME,
    PK_Table = PK.TABLE_NAME,
    PK_Column = PT.COLUMN_NAME,
    Constraint_Name = C.CONSTRAINT_NAME
FROM
    INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK
    ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK
    ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU
    ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
INNER JOIN (
            SELECT
                i1.TABLE_NAME,
                i2.COLUMN_NAME
            FROM
                INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
            INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2
                ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
            WHERE
                i1.CONSTRAINT_TYPE = 'PRIMARY KEY'
                AND I1.TABLE_NAME = [YOUR TABLE NAME]
           ) PT
    ON PT.TABLE_NAME = PK.TABLE_NAME

Friday, August 10, 2012

REST Client - Firefox addon


RESTClient, a debugger for RESTful web services.


Today i tried REST Client addon for fire fox browser , its really cool.

About this Add-on

RESTClient supports all HTTP methods RFC2616 (HTTP/1.1) and RFC2518 (WebDAV). You can construct custom HTTP request (custom method with resources URI and HTTP request Body) to directly test requests against a server.

For download this addon - click here

Monday, July 9, 2012

ADO.NET Entity Framework


The Microsoft® ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data access plumbing code that developers usually need to write. Using the Entity Framework, developers issue queries using LINQ, then retrieve and manipulate data as strongly typed objects. The Entity Framework’s ORM implementation provides services like change tracking, identity resolution, lazy loading, and query translation so that developers can focus on their application-specific business logic rather than the data access fundamentals.

High-level capabilities of the Entity Framework:

Works with a variety of database servers (including Microsoft SQL Server, Oracle, and DB2)
Includes a rich mapping engine that can handle real-world database schemas and works well with stored procedures
Provides integrated Visual Studio tools to visually create entity models and to auto-generate models from an existing database. New databases can be deployed from a model, which can also be hand-edited for full control
Provides a Code First experience to create entity models using code. Code First can map to an existing database or generate a database from the model.
Integrates well into all the .NET application programming models including ASP.NET, Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF), and WCF Data Services (formerly ADO.NET Data Services)
The Entity Framework is built on the existing ADO.NET provider model, with existing providers being updated additively to support the new Entity Framework functionality. Because of this, existing applications built on ADO.NET can be carried forward to the Entity Framework easily with a programming model that is familiar to ADO.NET developers.

Using the Entity Framework to write data-oriented applications provides the following benefits:
  • Reduced development time: the framework provides the core data access capabilities so developers can concentrate on application logic.
  • Developers can work in terms of a more application-centric object model, including types with inheritance, complex members, and relationships. In .NET Framework 4, the Entity Framework also supports Persistence Ignorance through Plain Old CLR Objects (POCO) entities.
  • Applications are freed from hard-coded dependencies on a particular data engine or storage schema by supporting a conceptual model that is independent of the physical/storage model.
  • Mappings between the object model and the storage-specific schema can change without changing the application code.
  • Language-Integrated Query support (called LINQ to Entities) provides IntelliSense and compile-time syntax validation for writing queries against a conceptual model.
More details please visit - http://msdn.microsoft.com/en-us/data/aa937709

Friday, June 15, 2012

JSON Parsing using JQuery

Takes a well-formed JSON string and returns the resulting JavaScript object.
  • version added: 1.4.1 

    usage  -- jQuery.parseJSON( json )

    json  --- The JSON string to parse.
Passing in a malformed JSON string may result in an exception being thrown. For example, the following are all malformed JSON strings:
  • {test: 1} (test does not have double quotes around it).
  • {'test': 1} ('test' is using single quotes instead of double quotes).
Additionally if you pass in nothing, an empty string, null, or undefined, 'null' will be returned from parseJSON. Where the browser provides a native implementation of JSON.parse, jQuery uses it to parse the string. For details on the JSON format, see http://json.org/.

Example:

Parse a JSON string.

var obj = jQuery.parseJSON('{"name":"John"}');
alert( obj.name === "John" );

Monday, April 23, 2012

How to view generated source by AJAX (or by JS)



One of the challenging things about debugging an AJAX application is that it isn't obvious how to view the html source that is being rendered by the browser after you have made modifications to it via an AJAX callback.  If you use the browser's built-in View Source command then it will show you the source that was used to render the original page, but it will not include any modifications made via javascript/AJAX calls.

If you are trying to view the generated source in Firefox, the simplest way is to first download and install the WebDeveloper extension   Then go to the View Source menu item and select "View Generated Source".
To view the generated source in IE you can type the following in the address bar


Monday, April 9, 2012

ASP.NET Profile Properties Overview

In many applications, you want to store and use information that is unique to a user. When a user visits your site, you can use the information you have stored to present the user with a personalized version of your Web application. Personalizing an application requires a number of elements: you must store the information using a unique user identifier, be able to recognize users when they visit again, and then fetch the user information as needed. To simplify your applications, you can use the ASP.NET profile feature, which can perform all of these tasks for you.

The ASP.NET profile feature associates information with an individual user and stores the information in a persistent format. Profiles allow you to manage user information without requiring you to create and maintain your own database. In addition, the ASP.NET profile feature makes the user information available using a strongly typed API that you can access from anywhere in your application.

You can store objects of any type using profiles. The profile feature provides a generic storage feature that allows you to define and maintain almost any kind of data while still making the data available in a type-safe manner.

You configure the profile feature by defining a list of properties whose values you want to maintain. For example, you might want to store the user's postal code so that your application can offer region-specific information, such as weather reports. In the configuration file, you would define a profile property named PostalCode. The profile section of the configuration file might look like the following:

  

When the user enters a postal code, you set a "profile" property to store the value for the current user, as in the following example:
Profile.PostalCode = txtPostalCode.Text;
 
When you want to use the value, you can get it in much the same way that
 you set it. For example, the following code example shows how to call 
an imaginary function named GetWeatherInfo, passing it the current user's postal code as stored in a profile: 

weatherInfo = GetWeatherInfo( Profile.PostalCode );
 
Please refer this MSDN article for more details.
 

Tuesday, March 6, 2012

JSONView - Firefox addon

Today i came across a firefox plug-in for viewing JSON Data.
After installing this plug in you can see JSON data formatted and highlighted in browser.
Can download JSON View from below link..
https://addons.mozilla.org/en-US/firefox/addon/jsonview/

Free REST service can try after installing JSON View.
http://api.worldbank.org/countries?format=json
 

ASP.NET Web API

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.

  • ASP.NET MVC includes ASP.NET Web API.
  • Choose either the Web Platform for Visual Studio 2010 or for Visual Studio 11, depending on which version you are running.
for samples , please visit -  http://www.asp.net/web-api/samples
for more details - http://www.asp.net/web-api

Monday, February 20, 2012

Single Page Application - ASP.Net

The ASP.NET Single Page Application (SPA) is a new feature in the ASP.NET MVC 4 beta preview. It provides a better end-to-end experience for building applications with significant client-side interactions using JavaScript.

   1. A set of JavaScript libraries for richer local interactions with cached data
   2. Additional Web API components for unit of work and DAL support
   3. An MVC project template with scaffolding to get started quickly



JavaScript Libraries

The JavaScript libraries include existing popular ones such as Knockout and History and a relatively new library called Upshot (formerly previewed as RIA/JS). Together they support presentation and editing of data across a set of pages that interact with local and remote data. They illustrate one prescriptive pattern of using distinct libraries together. You could also use them independently or replace one or more of them. For example, Upshot could be used with JsViews or jQuery UI or ISV controls and jQuery could be replaced with XUI. Some of the replacements may require some adaptation via a small library.

DataController on the Server

On the server-side, a new class called DataController which derives from ApiController, provides support for insert, update and delete operations in a unit of work with transaction support and automatic validations. It also provides a way to get the total count for paging along with the first page. It also provides a foundation for DAL-specific implementation of the above features. For example, DbController is a DataController that implements the above for Entity Framework Code First style of data access.

Single Page Application MVC Project Template

A new MVC project template for Single Page Application provides an educational tool and a way to start quickly. It includes scaffolding to generate a skeletal app that includes a DataController, optionally an Entity Framework DbContext and the scripts for basic query and edit tasks (CRUD operations). The template also includes a sample model class that you could use as is or replace with your favorite one to get started.

Can find more details from : http://www.asp.net/single-page-application/an-introduction-to-spa/overview/landingpage

Monday, February 6, 2012

Video and Audio with HTML 5

Yesterday i tried Video and Audio tags in HTML 5 , sharing some quick notes.
How It Works
To show a video in HTML5, this is all you need:


The control attribute adds video controls, like play, pause, and volume.
Video Formats and Browser Support

Browser
MP4
WebM
Ogg
Internet Explorer 9
YES
NO
NO
Firefox 4.0
NO
YES
YES
Google Chrome 6
YES
YES
YES
Apple Safari 5
YES
NO
NO
Opera 10.6
NO
YES
YES

MP4 = MPEG 4 files with H264 video codec and AAC audio codec
WebM = WebM files with VP8 video codec and Vorbis audio codec
Ogg = Ogg files with Theora video codec and Vorbis audio codec


To play an audio file in HTML5, this is all you need:




Audio Formats and Browser Support
Currently, there are 3 supported file formats for the

Browser
MP3
Wav
Ogg
Internet Explorer 9
YES
NO
NO
Firefox 4.0
NO
YES
YES
Google Chrome 6
YES
YES
YES
Apple Safari 5
YES
YES
NO
Opera 10.6
NO
YES
YES

Monday, January 16, 2012

Creating new Team project group in TFS

You can create security groups for your team project to better meet the security requirements of your organization. Creating a security group is an efficient way to grant a specific set of permissions to a group of users on your team project. Make sure that you allow only the minimum permissions necessary for the group, and add only those users or groups who must belong to this new team project group. If you must create a group that is not project-specific, consider creating a server-level group instead

Required Permissions

To perform this procedure, you must be a member of the Project Administrators group

To create a team project group

  1. In Team Explorer, select the team project for which you want to create a group.
  2. On the Team menu, point to Team Project Settings, and then click Group Membership.
  3. In the Project Groups dialog box, click New.
  4. In the Create New Team Foundation Server Group dialog box, in the Group Name box, type the name for the team project group.
  5. In the Description box, type a description for the group.
  6. Click OK.

Thursday, January 12, 2012

Insights to Knockout JS (KO)

Introduction

Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model. Any time you have sections of UI that update dynamically (e.g., changing depending on the user’s actions or when an external data source changes), KO can help you implement it more simply and maintainably.

Headline features:
  • Elegant dependency tracking - automatically updates the right parts of your UI whenever your data model changes
  • Declarative bindings - a simple and obvious way to connect parts of your UI to your data model
  • Flexible and sophisticated templating - construct a complex dynamic UI easily using arbitrarily nested templates
  • Trivially extensible - implement custom behaviors as new declarative bindings for easy reuse in just a few lines of code
Additional benefits:
  • Pure JavaScript library - works with any server or client-side technology
  • Can be added on top of your existing web application without requiring major architectural changes
  • Compact - around 25kb before gzipping
  • Works on any mainstream browser (IE 6+, Firefox 2+, Chrome, Safari, others)
  • Comprehensive suite of specifications (developed BDD-style) means its correct functioning can easily be verified on new browsers and platforms

Installation

Knockout’s core library is pure JavaScript and doesn’t depend on any other libraries. So, to add KO to your project, just follow these steps:
  1. Download the latest version of the Knockout JavaScript file from here. For normal development and production use, use the default, minified version (knockout-x.y.z.js).
    For debugging only, use the larger, non-minified version (knockout-x.y.z.debug.js). This behaves the same as the minified version, but has human-readable source code with full variable names and comments, and does not hide internal APIs.
  2. Reference the file using a

Friday, January 6, 2012

jStorage - store data locally with JavaScript

jStorage is a simple wrapper plugin for Prototype, MooTools and jQuery to cache data (string, numbers, objects, even XML nodes) on browser side. Note that functions, DOM nodes, host objects and such can not be saved.

jStorage makes use of HTML5 local storage where available and userData behavior in Internet Explorer older versions. Webkit SQLite is not supported.
Current availability: jStorage supports all major browsers - Internet Explorer 6+, Firefox 2+, Safari 4+, Chrome 4+, Opera 10.50+
If the browser doesn't support data caching, then no exceptions are raised - jStorage can still be used by the script but nothing is actually stored.
jStorage is really small, just about 2 kB when minified (under 1kB when gzipped)!

Browser Storage support Survives browser restart Survives browser crash Storage size
Chrome 4 + + + 5 MB
Firefox 3.6 + + + 5 MB
Firefox 3 + + + 5 MB
Firefox 2 + + + 5 MB
IE8 + + + 10 MB
IE7 + + + 128 kB
IE6 + + + 128 kB
Opera 10.50 + + - 5 MB
Opera 10.10 - N/A N/A N/A
Safari 4 + + + 5 MB
Iphone Safari + + + 5 MB
Safari 3 - N/A N/A N/A


jStorage can be downloaded at github (direct download link)


Thursday, December 29, 2011

ASP.Net - Different ways to transfer data between pages

1. Use the querystring:

protected void QueryStringButton_Click(object sender, EventArgs e)
         {
             Response.Redirect("QueryStringPage.aspx?Data=" + Server.UrlEncode(DataToSendTextBox.Text));
        }

2. Use HTTP POST:

<asp:Button ID="HttpPostButton" runat="server" Text="Use HttpPost"
             
PostBackUrl="~/HttpPostPage.aspx" onclick="HttpPostButton_Click"/>

protected void HttpPostButton_Click(object sender, EventArgs e)
        {
     // The PostBackUrl property of the Button takes care of where to send it!
        }

  3. Use Session State:

   protected void SessionStateButton_Click(object sender, EventArgs e)
         {
             Session["Data"] = DataToSendTextBox.Text;
             Response.Redirect("SessionStatePage.aspx");
        }

  4.  Use public properties:

   public string DataToSend
        {
            get
            {
                 return DataToSendTextBox.Text;
             }
        }

        protected void PublicPropertiesButton_Click(object sender, EventArgs e)
         {
             Server.Transfer("PublicPropertiesPage.aspx");
        }

5. Use PreviousPage Control Info:

protected void ControlInfoButton_Click(object sender, EventArgs e)
         {
             Server.Transfer("ControlInfoPage.aspx");
        }

  // target page:
protected void Page_Load(object sender, EventArgs e)
        {
            var textbox = PreviousPage.FindControl("DataToSendTextbox") as TextBox;
             if (textbox != null)
            {
                DataReceivedLabel.Text = textbox.Text;
            }
        }

6. Use HttpContext Items Collection:

  protected void HttpContextButton_Click(object sender, EventArgs e)
         {
             HttpContext.Current.Items["data"] = DataToSendTextBox.Text;
             Server.Transfer("HttpContextItemsPage.aspx");
        }

// target page:
protected void Page_Load(object sender, EventArgs e)
         {
             this.DataReceivedLabel.Text =(String) HttpContext.Current.Items["data"];
        }

7. Use Cookies:

protected void CookiesButton_Click(object sender, EventArgs e)
        {
            HttpCookie cook =  new HttpCookie("data");
            cook.Expires = DateTime.Now.AddDays(1);
            cook.Value = DataToSendTextBox.Text;
             Response.Cookies.Add(cook);
             Response.Redirect("HttpCookiePage.aspx");
        }

// target page:
protected void Page_Load(object sender, EventArgs e)
        {
            DataReceivedLabel.Text = Request.Cookies["data"].Value;
        }

8. Use Cache:

protected void CacheButton_Click(object sender, EventArgs e)
         {
             Cache["data"] = DataToSendTextBox.Text;
             Server.Transfer("CachePage.aspx");
        }
   // target page:
    protected void Page_Load(object sender, EventArgs e)
         {
             this.DataReceivedLabel.Text = (string) Cache["data"];
        }

Tuesday, December 20, 2011

SQL SERVER – 2008 – Insert Multiple Records Using One Insert Statement – Use of Row Constructor

SQL Server 2008 Method of Row Construction:
USE YourDB
GO
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES (
'First',1),
('Second',2),
('Third',3),
('Fourth',4),
('Fifth',5)