<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;Ck8CQH49cSp7ImA9WhRaEk0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624</id><updated>2012-02-13T22:27:41.069-08:00</updated><category term="MYSQL" /><category term="C#" /><category term="Asp.net 3.5" /><category term="Scripting" /><category term="JQuery" /><category term="SQL" /><category term=".net 3.5" /><category term="Linq" /><category term="Sql Server" /><category term="HTML" /><category term="Generic Collection" /><category term="Sql server 2008" /><category term="AJAX" /><category term=".net 2.0" /><category term="Session" /><category term="ASP.Net" /><category term="WPF" /><category term="Java Script" /><category term=".NET" /><category term="Sql server 2005" /><title>Yogesh Bhadauriya</title><subtitle type="html">Who Care! Who Regret!</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://yogeshyrbyogi.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>92</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/jsbM" /><feedburner:info uri="blogspot/jsbm" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;DUYASXg-fyp7ImA9WhRUFE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-7222895854914327977</id><published>2012-01-24T04:12:00.001-08:00</published><updated>2012-01-24T04:12:28.657-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-24T04:12:28.657-08:00</app:edited><title>Ideal SQL Query For Handling Error &amp; Transcation in MS SQL</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;br /&gt;
&lt;br /&gt;
BEGIN TRY&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;BEGIN TRAN&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;--put queries here&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;COMMIT;&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;br /&gt;
END TRY&lt;br /&gt;
BEGIN CATCH&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;IF @@TRANCOUNT&amp;gt;0&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;BEGIN&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;SELECT @@ERROR,ERROR_MESSAGE ( )&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;ROLLBACK;&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;END&lt;br /&gt;
END CATCH&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
any one can use above code to manage&amp;nbsp;transaction&amp;nbsp;as well as error handling in sql server.&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-7222895854914327977?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5TaXzUgV5GNah5yHLD2B0g0IhBM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5TaXzUgV5GNah5yHLD2B0g0IhBM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5TaXzUgV5GNah5yHLD2B0g0IhBM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5TaXzUgV5GNah5yHLD2B0g0IhBM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/jNU-DC6tkbM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/7222895854914327977/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2012/01/ideal-sql-query-for-handling-error.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7222895854914327977?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7222895854914327977?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/jNU-DC6tkbM/ideal-sql-query-for-handling-error.html" title="Ideal SQL Query For Handling Error &amp; Transcation in MS SQL" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2012/01/ideal-sql-query-for-handling-error.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EFQn8_cSp7ImA9WhZWEE4.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-7239476445134212968</id><published>2011-05-10T08:00:00.000-07:00</published><updated>2011-05-10T08:00:13.149-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-10T08:00:13.149-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Sql server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="Sql server 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>Capitalize the First Character of Each Word using queries</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I have found t-sql challenges question where they were asked to provide a solution of oracle INITCAP function in sql.&lt;br /&gt;
&lt;br /&gt;
I was started to find the solution of INITCAP function &amp;amp; found lots of user defined function.&lt;br /&gt;
&lt;br /&gt;
But here I have shared a solution where queries doesn't use any user defined function as well as any variable.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;pre class="brush:sql"&gt;&lt;/pre&gt;&lt;pre class="brush:sql"&gt;--First of all create one temp table    
DECLARE @t TABLE(ID INT IDENTITY, Data VARCHAR(1000))

--insert the sample data
INSERT INTO @t 
SELECT 'yogesh bhadauriya' 


--use the Common table expression
;with CTE AS
(

    --anchor query where we are finding the first character for replacing with uppercase
    SELECT Cast(STUFF(LOWER(Data), 1, 1, UPPER(LEFT(Data, 1))) As varchar(max)) As Data,
    PATINDEX('%[^a-zA-Z][a-z]%', Data COLLATE Latin1_General_Bin) As Position,ID,Data As OldData
    From @t
    
    Union All
    
   --recursive query
    SELECT Cast(STUFF(CTE.Data, Position, 2, UPPER(SUBSTRING(CTE.Data, CTE.Position, 2))) As Varchar(max)) as Data,
    Cast(PATINDEX('%[^a-zA-Z][a-z]%', CTE.Data COLLATE Latin1_General_Bin) As Int) As Position,CTE.ID,T.Data As OldData
    From @t As T
    Inner Join CTE On CTE.ID=CTE.ID
    where CTE.Data is not null
)
Select ID,OldData As Data,Data As Results
From CTE
where Data is not null
and Position=0


---output
--Id Data    Results
--1 yogesh bhadauriya Yogesh Bhadauriya
    &lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-7239476445134212968?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dOof4JKcGZxh03oCnkm4v04vtSE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dOof4JKcGZxh03oCnkm4v04vtSE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dOof4JKcGZxh03oCnkm4v04vtSE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dOof4JKcGZxh03oCnkm4v04vtSE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/DtEBYeQvjcA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/7239476445134212968/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2011/05/capitalize-first-character-of-each-word.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7239476445134212968?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7239476445134212968?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/DtEBYeQvjcA/capitalize-first-character-of-each-word.html" title="Capitalize the First Character of Each Word using queries" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2011/05/capitalize-first-character-of-each-word.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEGRHkzfSp7ImA9WhZXEEU.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-5624162888530194336</id><published>2011-04-29T07:50:00.000-07:00</published><updated>2011-04-29T07:50:25.785-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-29T07:50:25.785-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Sql server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="Sql server 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>User defined function to convert the number into charcter</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;How to convert the numeric value into its specific character? If this is your question, than create the following User Defined Function into your database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;--create the following function 
CREATE FUNCTION dbo.udf_Num_ToWords 
(
 @Number Numeric (38, 0) -- Input number with as many as 18 digits

) RETURNS VARCHAR(8000) 
/*
* Converts a integer number as large as 34 digits into the 
* equivalent words.  The first letter is capitalized.
*
* Attribution: Based on NumberToWords by Srinivas Sampath
*        as revised by Nick Barclay
*
* Example:
select dbo.udf_Num_ToWords (1234567890) + CHAR(10)
      +  dbo.udf_Num_ToWords (0) + CHAR(10)
      +  dbo.udf_Num_ToWords (123) + CHAR(10)
select dbo.udf_Num_ToWords(76543210987654321098765432109876543210)
 
DECLARE @i numeric (38,0)
SET @i = 0
WHILE @I &amp;lt;= 1000 BEGIN 
    PRINT convert (char(5), @i)  
            + convert(varchar(255), dbo.udf_Num_ToWords(@i)) 
    SET @I  = @i + 1 
END
*
* Published as the T-SQL UDF of the Week Vol 2 #9 2/17/03
****************************************************************/
AS BEGIN

DECLARE @inputNumber VARCHAR(38)
DECLARE @NumbersTable TABLE (number CHAR(2), word VARCHAR(10))
DECLARE @outputString VARCHAR(8000)
DECLARE @length INT
DECLARE @counter INT
DECLARE @loops INT
DECLARE @position INT
DECLARE @chunk CHAR(3) -- for chunks of 3 numbers
DECLARE @tensones CHAR(2)
DECLARE @hundreds CHAR(1)
DECLARE @tens CHAR(1)
DECLARE @ones CHAR(1)

IF @Number = 0 Return 'Zero'

-- initialize the variables
SELECT @inputNumber = CONVERT(varchar(38), @Number)
     , @outputString = ''
     , @counter = 1
SELECT @length   = LEN(@inputNumber)
     , @position = LEN(@inputNumber) - 2
     , @loops    = LEN(@inputNumber)/3

-- make sure there is an extra loop added for the remaining numbers
IF LEN(@inputNumber) % 3 &amp;lt;&amp;gt; 0 SET @loops = @loops + 1

-- insert data for the numbers and words
INSERT INTO @NumbersTable   SELECT '00', ''
    UNION ALL SELECT '01', 'one'      UNION ALL SELECT '02', 'two'
    UNION ALL SELECT '03', 'three'    UNION ALL SELECT '04', 'four'
    UNION ALL SELECT '05', 'five'     UNION ALL SELECT '06', 'six'
    UNION ALL SELECT '07', 'seven'    UNION ALL SELECT '08', 'eight'
    UNION ALL SELECT '09', 'nine'     UNION ALL SELECT '10', 'ten'
    UNION ALL SELECT '11', 'eleven'   UNION ALL SELECT '12', 'twelve'
    UNION ALL SELECT '13', 'thirteen' UNION ALL SELECT '14', 'fourteen'
    UNION ALL SELECT '15', 'fifteen'  UNION ALL SELECT '16', 'sixteen'
    UNION ALL SELECT '17', 'seventeen' UNION ALL SELECT '18', 'eighteen'
    UNION ALL SELECT '19', 'nineteen' UNION ALL SELECT '20', 'twenty'
    UNION ALL SELECT '30', 'thirty'   UNION ALL SELECT '40', 'forty'
    UNION ALL SELECT '50', 'fifty'    UNION ALL SELECT '60', 'sixty'
    UNION ALL SELECT '70', 'seventy'  UNION ALL SELECT '80', 'eighty'
    UNION ALL SELECT '90', 'ninety'   

WHILE @counter &amp;lt;= @loops BEGIN

 -- get chunks of 3 numbers at a time, padded with leading zeros
 SET @chunk = RIGHT('000' + SUBSTRING(@inputNumber, @position, 3), 3)

 IF @chunk &amp;lt;&amp;gt; '000' BEGIN
  SELECT @tensones = SUBSTRING(@chunk, 2, 2)
       , @hundreds = SUBSTRING(@chunk, 1, 1)
       , @tens = SUBSTRING(@chunk, 2, 1)
       , @ones = SUBSTRING(@chunk, 3, 1)

  -- If twenty or less, use the word directly from @NumbersTable
  IF CONVERT(INT, @tensones) &amp;lt;= 20 OR @Ones='0' BEGIN
   SET @outputString = (SELECT word 
                                      FROM @NumbersTable 
                                      WHERE @tensones = number)
                   + CASE @counter WHEN 1 THEN '' -- No name
                       WHEN 2 THEN ' thousand ' WHEN 3 THEN ' thousand '
                       WHEN 4 THEN ' billion '  WHEN 5 THEN ' trillion '
                       WHEN 6 THEN ' quadrillion ' WHEN 7 THEN ' quintillion '
                       WHEN 8 THEN ' sextillion '  WHEN 9 THEN ' septillion '
                       WHEN 10 THEN ' octillion '  WHEN 11 THEN ' nonillion '
                       WHEN 12 THEN ' decillion '  WHEN 13 THEN ' undecillion '
                       ELSE '' END
                               + @outputString
      END
   ELSE BEGIN -- break down the ones and the tens separately

             SET @outputString = ' ' 
                            + (SELECT word 
                                    FROM @NumbersTable 
                                    WHERE @tens + '0' = number)
              + '-'
                             + (SELECT word 
                                    FROM @NumbersTable 
                                    WHERE '0'+ @ones = number)
                   + CASE @counter WHEN 1 THEN '' -- No name
                       WHEN 2 THEN ' thousand ' WHEN 3 THEN ' million '
                       WHEN 4 THEN ' billion '  WHEN 5 THEN ' trillion '
                       WHEN 6 THEN ' quadrillion ' WHEN 7 THEN ' quintillion '
                       WHEN 8 THEN ' sextillion '  WHEN 9 THEN ' septillion '
                       WHEN 10 THEN ' octillion '  WHEN 11 THEN ' nonillion '
                       WHEN 12 THEN ' decillion '   WHEN 13 THEN ' undecillion '
                       ELSE '' END
                            + @outputString
  END

  -- now get the hundreds
  IF @hundreds &amp;lt;&amp;gt; '0' BEGIN
   SET @outputString  = (SELECT word 
                                      FROM @NumbersTable 
                                      WHERE '0' + @hundreds = number)
                 + ' hundred ' 
                                + @outputString
  END
 END

 SELECT @counter = @counter + 1
      , @position = @position - 3

END

-- Remove any double spaces
SET @outputString = LTRIM(RTRIM(REPLACE(@outputString, '  ', ' ')))
SET @outputstring = UPPER(LEFT(@outputstring, 1)) + SUBSTRING(@outputstring, 2, 8000)


RETURN @outputString -- return the result
END




&lt;/pre&gt;&lt;br /&gt;
To check the output of the above User Defined Function, execute the below query into your database.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;--now run the following query to get the result

select dbo.udf_Num_ToWords(5800000)

--output
--Five thousand eight hundred thousand
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
Happy Coding to All&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-5624162888530194336?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Bw9qrPeTvBJQpYLqiR5EWRfXkSI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Bw9qrPeTvBJQpYLqiR5EWRfXkSI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Bw9qrPeTvBJQpYLqiR5EWRfXkSI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Bw9qrPeTvBJQpYLqiR5EWRfXkSI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/RQSgbS_qmXw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/5624162888530194336/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2011/04/user-defined-function-to-convert-number.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/5624162888530194336?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/5624162888530194336?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/RQSgbS_qmXw/user-defined-function-to-convert-number.html" title="User defined function to convert the number into charcter" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2011/04/user-defined-function-to-convert-number.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUDSXY_cSp7ImA9WhZXEEU.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-1564215573099026333</id><published>2011-04-29T07:44:00.000-07:00</published><updated>2011-04-29T07:44:38.849-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-29T07:44:38.849-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Sql server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>Recursive Query To Find All Child Node in SQL server 2005+</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;How to find the all child of particular parent using the Recursive Query&lt;br /&gt;
&lt;pre class="brush:sql"&gt;--here we are creating the table variable so that we can insert some dummy record
Declare @Table Table
(
 TId int,
 ParentId int,
 Name varchar(10)
)
--inserting some records
--using the union all to insert more than one records
insert into @Table
Select 1,NULL,'ICT'
Union All
Select 2,1,'ICT-M1'
Union All
Select 4,1,'ICT-M2'
Union All
Select 7,2,'ICT-M1U1'
Union All
Select 8,2,'ICT-M1U2'
Union All
Select 9,4,'ICT-M2U1'
Union All
Select 10,4,'ICT-M2U2'
Union All
Select 11,7,'ICT-M1U1P1'
Union All
Select 12,7,'ICT-M1U1P2'
Union All
Select 13,8,'ICT-M1U2P1'
Union All
Select 14,8,'ICT-M1U2P2'
Union All
Select 15,9,'ICT-M2U1P1'
Union All
Select 16,9,'ICT-M2U1P2'
Union All
Select 17,10,'ICT-M2U2P1'
Union All
Select 18,10,'ICT-M2U2P2'

--variable to hold data
Declare @ChildNode varchar(1000)
Set @ChildNode='';

 
--use the standard recursive query
;with [CTE] as 
(
 --anchor query where we are finding the all parents
    select TId,ParentId,Name,CAST(ISNULL(CAST(ParentId as varchar(10)),'0') As Varchar(100)) As ChildNode
    from @Table c where c.[ParentId] is null

    union all

 --recursive query where we are finding the all child according to anchor query parent
    select c.TId,c.ParentId,c.Name,
    CAST( p.ChildNode +','+cast(c.TId as varchar(10) ) As Varchar(100)) As ChildNode
    from [CTE] p, @Table c where c.[ParentId] = p.[TId]    
)
--select the child node as per the id
--Assigin the all Ids into  one variable
select @ChildNode=@ChildNode+','+Cast(TId as varchar(10))
from [CTE]
Cross Apply
dbo.Split(ChildNode,',')
where items=9
order by TId

select SUBSTRING(@ChildNode,2,LEN(@ChildNode))

--outpu
--2,7,8,11,12,13,14


----
--create the tabular function to split the multi valued into table
Create FUNCTION [dbo].[Split](@String varchar(8000), @Delimiter char(1))     
returns @temptable TABLE (items varchar(8000))     
as     
begin     
 declare @idx int     
 declare @slice varchar(8000)     
    
 select @idx = 1     
  if len(@String)&amp;lt;1 or @String is null  return     
    
 while @idx!= 0     
 begin     
  set @idx = charindex(@Delimiter,@String)     
  if @idx!=0     
   set @slice = left(@String,@idx - 1)     
  else     
   set @slice = @String     
  
  if(len(@slice)&amp;gt;0)
   insert into @temptable(Items) values(@slice)     

  set @String = right(@String,len(@String) - @idx)     
  if len(@String) = 0 break     
 end 
return     
end


&lt;/pre&gt;&lt;pre class="code"&gt;--&lt;/pre&gt;&lt;pre class="code"&gt;Happy Coding&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-1564215573099026333?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/eCh5yO76GRwSE5ga9N4pxoC0oCc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/eCh5yO76GRwSE5ga9N4pxoC0oCc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/eCh5yO76GRwSE5ga9N4pxoC0oCc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/eCh5yO76GRwSE5ga9N4pxoC0oCc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/7wwT9FGdQtg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/1564215573099026333/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2011/04/recursive-query-to-find-all-child-node.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/1564215573099026333?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/1564215573099026333?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/7wwT9FGdQtg/recursive-query-to-find-all-child-node.html" title="Recursive Query To Find All Child Node in SQL server 2005+" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2011/04/recursive-query-to-find-all-child-node.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UAQ3Y9fyp7ImA9WhZRGU8.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-1529894594812012758</id><published>2011-04-15T20:40:00.000-07:00</published><updated>2011-04-15T20:40:42.867-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-15T20:40:42.867-07:00</app:edited><title>How to insert multiple record using xml in sql server 2005+</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;How to insert the multiple record using the xml into sql server, please check the following example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @idoc int
DECLARE @doc varchar(max)
SET @doc ='
&amp;lt;ROOT&amp;gt;
 &amp;lt;Trans TransId="1" Add="false" Edit="true" Delete="true" View="true" Block="false"&amp;gt;   
 &amp;lt;/Trans&amp;gt;
 &amp;lt;Trans TransId="2" Add="1" Edit="1" Delete="1" View="1" Block="0"&amp;gt;   
 &amp;lt;/Trans&amp;gt;
&amp;lt;/ROOT&amp;gt;'

--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
-- Execute a SELECT statement that uses the OPENXML rowset provider.


SELECT *
Into #TempTable 
FROM OPENXML(@idoc, '/ROOT/Trans',1)
WITH 
( 
 TransId  varchar(10),
    [Add] bit,
    Edit bit,
    [Delete] bit,
    [View] bit,
    Block bit
)

Select * From #TempTable

drop table #TempTable

&lt;/pre&gt;&lt;pre class="code"&gt;--&lt;/pre&gt;&lt;pre class="code"&gt;happy coding &lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-1529894594812012758?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mKkhzJ9bOlHrrN1hCKDHuNvHwBw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mKkhzJ9bOlHrrN1hCKDHuNvHwBw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mKkhzJ9bOlHrrN1hCKDHuNvHwBw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mKkhzJ9bOlHrrN1hCKDHuNvHwBw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/v5feJq-yKWs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/1529894594812012758/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2011/04/how-to-insert-multiple-record-using-xml.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/1529894594812012758?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/1529894594812012758?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/v5feJq-yKWs/how-to-insert-multiple-record-using-xml.html" title="How to insert multiple record using xml in sql server 2005+" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2011/04/how-to-insert-multiple-record-using-xml.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEcHRXsyfSp7ImA9Wx9RE08.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-2774993737100964781</id><published>2010-12-14T01:57:00.000-08:00</published><updated>2010-12-14T02:20:34.595-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-14T02:20:34.595-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Performance Comparision Between For, While and Foreach Loop</title><content type="html">Today I was posted one post regarding list to datatable conversion. But one of the my senior told me that try to avoid foreach loop.&lt;br /&gt;
&lt;br /&gt;
So that I was googled/binged regarding the same.&lt;br /&gt;
&lt;br /&gt;
Here I am showing you some figure for the same here.&lt;br /&gt;
&lt;br /&gt;
Using the System.Diagnostics.Stopwatch class I ran some tests. 100,000  iterations in a for loop that did nothing inside took me 0.0003745  seconds. This was the code for the loop:&lt;br /&gt;
&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;pre class="brush:csharp"&gt;for (int i = 0; i &amp;lt; 100000; i++) ;
&lt;/pre&gt;&lt;br /&gt;
The while loop resulted 0.0003641 seconds, which is pretty much the same as the for loop. Here is the code I used: &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;int i=0;
while (i &amp;lt; 100000)
 i++;
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="coloredcode"&gt;&amp;nbsp;&lt;/pre&gt;The foreach loop has a slightly different purpose. It is  meant for itterating through some collection that implements  IEnumerable. It's performance is much slower, my test resulted in  0.0009076 seconds with this code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;int[] test = new int[100000];
foreach (int i in test) ;
&lt;/pre&gt;&lt;br /&gt;
foreach creates an instance of an enumerator (returned from  GetEnumerator) and that enumerator also keeps state throughout the  course of the foreach loop. It then repeatedly calls for the Next()  object on the enumerator and runs your code for each object it returns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, it seems that 'while' is the fastest looping technique among the  three available techniques in C#, &amp;nbsp;for a given processing within the  loop. Right?&lt;br /&gt;
&lt;br /&gt;
It varies. "while" and "for" have pretty much the same results. While had a slight advantage, but not one that great.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Im not an expert, but I have the feeling that a while and for loop,  once compiled to MSLI, probably are both the exact same thing.&lt;br /&gt;
&lt;br /&gt;
And  I wouldn't be surprised if foreach was faster when iterating through  objects, since the optimizer can "expect" whats going to happen... So  I'd go with foreach being faster if you can use it, and the 2 others  being the same thing, if foreach isn't applicable.&lt;br /&gt;
&lt;br /&gt;
My logic here  is that if you're looping through a collection, and you use a for loop  for example, you're going to have to use the index of the collection,  which depending on implementation, could be a minor performance hit to  "seek" the object, as opposed to going through a well written iterator.&lt;br /&gt;
&lt;br /&gt;
Just an example.So really: I wouldn't care too much about  performance of these loops. This isn't C/C++, and when you compile, its  not native code (at first). So it is safe to assume that the solution  that seems the most efficient "logically" will be so in practice.&lt;br /&gt;
&lt;br /&gt;
For each is slower for a number of reasons. One is it is using the  IEnumerable interface, which requires some casting (assuming you aren't  using a generic collection).&amp;nbsp;My test above seemed to go along with that  as well.&amp;nbsp;A simple for/while/do loop is pretty much as simple as it gets.&lt;br /&gt;
&lt;br /&gt;
As for the MSIL code, let's take a look. This is the MSIL for the for loop:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;IL_0000:  nop
  IL_0001:  ldc.i4.0
  IL_0002:  stloc.0
  IL_0003:  br.s       IL_0009
  IL_0005:  ldloc.0
  IL_0006:  ldc.i4.1
  IL_0007:  add
  IL_0008:  stloc.0
  IL_0009:  ldloc.0
  IL_000a:  ldc.i4     0x186a0
  IL_000f:  clt
  IL_0011:  stloc.1
  IL_0012:  ldloc.1
  IL_0013:  brtrue.s   IL_0005
&lt;/pre&gt;&lt;br /&gt;
And here it is for the while loop:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;IL_0000:  nop
  IL_0001:  ldc.i4.0
  IL_0002:  stloc.0
  IL_0003:  br.s       IL_0009
  IL_0005:  ldloc.0
  IL_0006:  ldc.i4.1
  IL_0007:  add
  IL_0008:  stloc.0
  IL_0009:  ldloc.0
  IL_000a:  ldc.i4     0x186a0
  IL_000f:  clt
  IL_0011:  stloc.1
  IL_0012:  ldloc.1
  IL_0013:  brtrue.s   IL_0005
&lt;/pre&gt;&lt;br /&gt;
So yes, they are exactly identical.&lt;br /&gt;
&lt;br /&gt;
Although very handy, C#'s &lt;code&gt;foreach&lt;/code&gt; statement is actually quite dangerous.  In fact, I may swear off its use entirely. Why? Two reasons: &lt;b&gt;(1) performance, and  (2) predictability.&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Performance&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Iterating through a collection using &lt;code&gt;foreach&lt;/code&gt; is slower than with &lt;code&gt;for&lt;/code&gt;. I can't remember where I first learned that, perhaps in &lt;a href="http://msdn.microsoft.com/en-us/library/ms998547.aspx"&gt;Patterns &amp;amp; Practices:  Improving .Net Application Performance&lt;/a&gt;. Maybe it was from personal experience.  How much slower? Well, I suppose that depends on your particular circumstances.  Here are a few interesting references:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/KB/cs/foreach.aspx"&gt;FOREACH Vs. FOR   (C#)&lt;/a&gt;: shows the extra IL code created for a &lt;code&gt;foreach&lt;/code&gt; loop&lt;/li&gt;
&lt;li&gt;  &lt;a href="http://blogs.msdn.com/kevin_ransom/archive/2004/04/19/116072.aspx"&gt;  To foreach or not to foreach that is the question&lt;/a&gt;: claims it isn't so clear-cut,   at least for regular arrays. Not absolutely conclusive.&lt;/li&gt;
&lt;/ul&gt;&lt;h2 style="font-weight: normal;"&gt;&lt;b&gt;&lt;span style="font-size: small;"&gt;Predictability&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;&lt;h2 style="font-weight: normal;"&gt;&lt;span style="font-size: small;"&gt;I was looking at the C# Reference entry for &lt;a href="http://msdn.microsoft.com/en-us/library/ttw7t8t6%28VS.80%29.aspx"&gt;foreach&lt;/a&gt;  today and noticed this for the first time (italics added by me):&lt;/span&gt;  &lt;/h2&gt;&lt;blockquote&gt;The &lt;b&gt;foreach&lt;/b&gt; statement is used to iterate through the collection to get   the desired information, but should not be used to change the contents of the   collection to avoid &lt;code&gt;unpredictable side effects&lt;/code&gt;.&lt;/blockquote&gt;What's that all about? Let's take this as an example:&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;foreach(MyClass myObj in List&lt;myclass&gt;)&lt;/myclass&gt;&lt;/pre&gt;Looking deeper into the &lt;a href="http://msdn.microsoft.com/en-us/library/ms228593%28VS.80%29.aspx"&gt;C# Language  Specification&lt;/a&gt;... the iteration variable is supposed to be read-only, though  apparently that doesn't stop you from updating a property of an object. Thus for  instance it would be illegal to assign a new value to &lt;code&gt;myObj&lt;/code&gt;, but not  to assign a new value to &lt;code&gt;myObj.MyProperty&lt;/code&gt;. &lt;br /&gt;
And that's all I can find. Why are there unpredictable side effects? I don't  know. But seems best to heed Microsoft's warning.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;&lt;span style="font-size: small;"&gt;Conclusion&lt;/span&gt;&lt;/h2&gt;Some argue that you shouldn't code for performance from the beginning, and therefore  go ahead and use &lt;code&gt;foreach&lt;/code&gt; whenever you want so long as you don't update  the values. In my experience that's hogwash — most of the code I work on goes into  environments where performance is extremely important. Besides, writing a for statement  requires very little extra coding compared to a &lt;code&gt;foreach&lt;/code&gt; statement.  Furthermore, if you have a lot going on inside your iteration block, it can be easy  to forget and accidentally update the iteration variable inside a &lt;code&gt;foreach&lt;/code&gt;   loop. Thus do I conclude: just avoid &lt;code&gt;foreach&lt;/code&gt; altogether.&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style="font-weight: normal;"&gt;&lt;b&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;Honestly the academically correct answer is "It's Irrelevant".&amp;nbsp; You cant  optimize performance by somehow picking "the best loop".&amp;nbsp; If you're  doing performance optimizations you should start with a Big O analysis  of your algorithms and Profiling.&amp;nbsp; You'd be amazed at how much faster  keeping around a dictionary for lookups or using a sorted list + binary  search is than looping over a list every time you need to find an  object.&lt;br /&gt;
&lt;br /&gt;
Doing so will give you unnoticeable performance increases at the cost  of maintainability and programmer time and the effort you're putting in  to such small performance boosts is better spent on a proper design and  implementation.&amp;nbsp;&amp;nbsp; Let's take a real world example of finding duplicates  in a list to illustrate my point:&lt;br /&gt;
first let's assume that comparing two items is O(1).&amp;nbsp; We can implement this any number of ways, two of which are:&lt;br /&gt;
&lt;br /&gt;
A)  use nested loops with i on the outer loop and j on the inner loop, when  list[i] == list[j] push the pair onto a list of duplicates.&lt;br /&gt;
B)  copy the list to tmpList.&amp;nbsp; quicksort tmpList.&amp;nbsp; iterate over the list  with i, when list[i] == list[i+1] push the pair onto the list of  duplicates&lt;br /&gt;
&lt;br /&gt;
No amount of optimization can change the fact that A runs in O(n^2) while B runs in O(2*n+n*log(n)).&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-2774993737100964781?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/p_vvEz0rQtfEnVzCAvThTdCWn6A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p_vvEz0rQtfEnVzCAvThTdCWn6A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/p_vvEz0rQtfEnVzCAvThTdCWn6A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p_vvEz0rQtfEnVzCAvThTdCWn6A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/eSqNqu_bW_g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/2774993737100964781/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/12/performance-comparision-between-for.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/2774993737100964781?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/2774993737100964781?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/eSqNqu_bW_g/performance-comparision-between-for.html" title="Performance Comparision Between For, While and Foreach Loop" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/12/performance-comparision-between-for.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UNRn48eCp7ImA9Wx9RE0w.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-8762462846177855438</id><published>2010-12-13T23:21:00.000-08:00</published><updated>2010-12-13T23:21:37.070-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-13T23:21:37.070-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="Generic Collection" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 3.5" /><title>Convert List to DataTable</title><content type="html">One day I confused to convert the List collection to datatable object. I was wondering how to iterate the columns wise and rows wise in list to make some calculation.&lt;br /&gt;
&lt;br /&gt;
I got the solution which was posted below:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;public DataTable ListToDataTable&lt;t&gt;(IEnumerable&lt;t&gt; list)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; var dt = new DataTable();

&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (var info in typeof(T).GetProperties())
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dt.Columns.Add(new DataColumn(info.Name, info.PropertyType));
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (var t in list)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var row = dt.NewRow();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (var info in typeof(T).GetProperties())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[info.Name] = info.GetValue(t, null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dt.Rows.Add(row);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return dt;
}&lt;/t&gt;&lt;/t&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;t&gt;&lt;t&gt;--&lt;/t&gt;&lt;/t&gt;&lt;br /&gt;
&lt;t&gt;&lt;t&gt;Happy coding.&lt;/t&gt;&lt;/t&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-8762462846177855438?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jZIB0ikbK2GVX2DnaJSIeIXJH30/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jZIB0ikbK2GVX2DnaJSIeIXJH30/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jZIB0ikbK2GVX2DnaJSIeIXJH30/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jZIB0ikbK2GVX2DnaJSIeIXJH30/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/UOVIm6Q7xDE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/8762462846177855438/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/12/convert-list-to-datatable.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/8762462846177855438?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/8762462846177855438?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/UOVIm6Q7xDE/convert-list-to-datatable.html" title="Convert List to DataTable" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/12/convert-list-to-datatable.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0UDRXw6fCp7ImA9WxFXEkg.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-4144187982747025419</id><published>2010-05-19T01:54:00.000-07:00</published><updated>2010-05-19T01:54:34.214-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-19T01:54:34.214-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>Age calculation with SQL Server</title><content type="html">There seem to be many different methods being suggested to calculate  an age in SQLServer.&amp;nbsp; Some are quite complex but most are simply wrong.&amp;nbsp;  This is by far the simplest and accurate method that I know.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;Declare &lt;/span&gt;@Date1 &lt;span style="color: blue;"&gt;datetime
Declare &lt;/span&gt;@Date2 &lt;span style="color: blue;"&gt;datetime


Select &lt;/span&gt;@Date1 &lt;span style="color: grey;"&gt;= &lt;/span&gt;&lt;span style="color: red;"&gt;'15Feb1971'&lt;/span&gt;&lt;span style="color: blue;"&gt;Select &lt;/span&gt;@Date2 &lt;span style="color: grey;"&gt;= &lt;/span&gt;&lt;span style="color: red;"&gt;'08Dec2009'&lt;/span&gt;&lt;span style="color: blue;"&gt;select CASE
WHEN &lt;/span&gt;&lt;span style="color: magenta;"&gt;dateadd&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;year&lt;/span&gt;&lt;span style="color: grey;"&gt;, &lt;/span&gt;&lt;span style="color: magenta;"&gt;datediff &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;year&lt;/span&gt;&lt;span style="color: grey;"&gt;, &lt;/span&gt;@Date1&lt;span style="color: grey;"&gt;, &lt;/span&gt;@Date2&lt;span style="color: grey;"&gt;), &lt;/span&gt;@Date1&lt;span style="color: grey;"&gt;) &amp;gt; &lt;/span&gt;@Date2
&lt;span style="color: blue;"&gt;THEN &lt;/span&gt;&lt;span style="color: magenta;"&gt;datediff &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;year&lt;/span&gt;&lt;span style="color: grey;"&gt;, &lt;/span&gt;@Date1&lt;span style="color: grey;"&gt;, &lt;/span&gt;@Date2&lt;span style="color: grey;"&gt;) - &lt;/span&gt;1
&lt;span style="color: blue;"&gt;ELSE &lt;/span&gt;&lt;span style="color: magenta;"&gt;datediff &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;year&lt;/span&gt;&lt;span style="color: grey;"&gt;, &lt;/span&gt;@Date1&lt;span style="color: grey;"&gt;, &lt;/span&gt;@Date2&lt;span style="color: grey;"&gt;)&lt;/span&gt;&lt;span style="color: blue;"&gt;END as &lt;/span&gt;Age&lt;/pre&gt;&lt;pre class="code"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="code"&gt;--&lt;/pre&gt;&lt;pre class="code"&gt;happy coding &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-4144187982747025419?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9EJg7Hj28XD91_rjGZ92jgdD57c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9EJg7Hj28XD91_rjGZ92jgdD57c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9EJg7Hj28XD91_rjGZ92jgdD57c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9EJg7Hj28XD91_rjGZ92jgdD57c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/R5Rj3xZBQ6U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/4144187982747025419/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/05/age-calculation-with-sql-server.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/4144187982747025419?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/4144187982747025419?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/R5Rj3xZBQ6U/age-calculation-with-sql-server.html" title="Age calculation with SQL Server" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/05/age-calculation-with-sql-server.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0MDQ34zfyp7ImA9WxFSFks.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-7257080173832212834</id><published>2010-04-19T01:24:00.000-07:00</published><updated>2010-04-19T01:24:32.087-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-19T01:24:32.087-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 3.5" /><title>[WPF] How to assign a dynamic resource from code-behind ?</title><content type="html">When working on WPF projects, it’s mandatory to assign resources to  user interface controls. When you work in XAML, it’s pretty simple: you  just need to use the &lt;em&gt;MarkupExtension&lt;/em&gt; named &lt;strong&gt;StaticResource&lt;/strong&gt;  (or &lt;strong&gt;DynamicResource&lt;/strong&gt; if the resource is going to be  modified):&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 &lt;\cf3 Button\cf0  Content=\cf4 "Find Position"\cf0  Click=\cf4 "Button_Click"\cf0  Background=\cf4 "\{DynamicResource brush\}"\cf0  /&gt;} --&gt;&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; color: black; font-family: consolas; font-size: 10pt;"&gt;   &lt;div style="margin: 0px;"&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;Button&lt;/span&gt; Content=&lt;span style="color: #a31515;"&gt;"Find Position"&lt;/span&gt; Click=&lt;span style="color: #a31515;"&gt;"Button_Click"&lt;/span&gt; Background=&lt;span style="color: #a31515;"&gt;"{DynamicResource brush}"&lt;/span&gt; /&amp;gt;&lt;/div&gt;&lt;/div&gt;But, how to do the same using code-behind ? The key  is to use the method &lt;strong&gt;SetResourceReference&lt;/strong&gt; (&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.setresourcereference.aspx" title="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.setresourcereference.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.setresourcereference.aspx&lt;/a&gt;):&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red163\green21\blue21;\red0\green0\blue255;}??\fs20                 &lt;\cf3 Window\cf0 .Resources&gt;\par ??\par ??    &lt;solidcolorbrush x:\cf3 Key\cf0 =\cf4 "brush"\cf0  Color=\cf4 "Red"\cf0  /&gt;\par ??\par ??&lt;/\cf3 Window\cf0 .Resources&gt;\par ??\par ?? \par ??\par ??&lt;button x:Name=\cf4 "btn"\cf0 Content=\cf4 "Find Position"\cf0  Click=\cf4 "Button_Click"\cf0  /&gt;\par ??\par ??\par ??\par ??\cf5 this\cf0 .btn.SetResourceReference(BackgroundProperty, \cf4 "brush"\cf0 );\par ??} --&gt;&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; color: black; font-family: consolas; font-size: 10pt;"&gt;   &lt;div style="margin: 0px;"&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;Window&lt;/span&gt;.Resources&amp;gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;solidcolorbrush x:=""&gt;&lt;span style="color: #2b91af;"&gt;Key&lt;/span&gt;=&lt;span style="color: #a31515;"&gt;"brush"&lt;/span&gt; Color=&lt;span style="color: #a31515;"&gt;"Red"&lt;/span&gt; /&amp;gt;&lt;/solidcolorbrush&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;!--&lt;span style="color: rgb(43, 145, 175);"--&gt;Window.Resources&amp;gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;button style="color: #a31515;" x:name="&amp;lt;span"&gt;"btn"Content=&lt;span style="color: #a31515;"&gt;"Find Position"&lt;/span&gt; Click=&lt;span style="color: #a31515;"&gt;"Button_Click"&lt;/span&gt; /&amp;gt; &lt;/button&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;this&lt;/span&gt;.btn.SetResourceReference(BackgroundProperty,  &lt;span style="color: #a31515;"&gt;"brush"&lt;/span&gt;);&lt;/div&gt;&lt;/div&gt;As you can see, it’s really simple to use: you define the resource,  you define the control and, in code behind, you call the method &lt;em&gt;SetResourceReference&lt;/em&gt;  and use the following parameters:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;the  DependencyProperty on which the resource will be applied&lt;/li&gt;
&lt;li&gt;the  name of the resource&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Happy coding !&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-7257080173832212834?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/iJRYx77Bc2yFZROocVPkhrPfb1g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iJRYx77Bc2yFZROocVPkhrPfb1g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/iJRYx77Bc2yFZROocVPkhrPfb1g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iJRYx77Bc2yFZROocVPkhrPfb1g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/i-ykGvwshtQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/7257080173832212834/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/04/wpf-how-to-assign-dynamic-resource-from.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7257080173832212834?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7257080173832212834?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/i-ykGvwshtQ/wpf-how-to-assign-dynamic-resource-from.html" title="[WPF] How to assign a dynamic resource from code-behind ?" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/04/wpf-how-to-assign-dynamic-resource-from.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkMER345eip7ImA9WxBUEEw.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-7930376740982973673</id><published>2010-02-24T03:20:00.000-08:00</published><updated>2010-02-24T03:20:06.022-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-24T03:20:06.022-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Sql server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>Reset Identity Column Value in SQL Server</title><content type="html">If you are using an identity column on your SQL Server tables, you can set the next insert value to whatever value you want. An example is if you wanted to start numbering your ID column at 1000 instead of 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It would be wise to first check what the current identify value is. We can use this command to do so:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DBCC CHECKIDENT ('tablename', NORESEED)&amp;nbsp;&lt;/pre&gt;&lt;pre class="brush:sql"&gt;&amp;nbsp;&lt;/pre&gt;For instance, if I wanted to check the next ID value of my orders table, I could use this command:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DBCC CHECKIDENT (orders, NORESEED)&amp;nbsp;&lt;/pre&gt;&lt;pre class="brush:sql"&gt;&amp;nbsp;&lt;/pre&gt;To set the value of the next ID to be 1000, I can use this command:&lt;br /&gt;
DBCC CHECKIDENT (orders, RESEED, 999)  &lt;br /&gt;
&lt;br /&gt;
Note that the next value will be whatever you reseed with + 1, so in this case I set it to 999 so that the next value will be 1000.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another thing to note is that you may need to enclose the table name in single quotes or square brackets if you are referencing by a full path, or if your table name has spaces in it. (which it really shouldn’t)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DBCC CHECKIDENT ('databasename.dbo.orders',RESEED, 999)
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-7930376740982973673?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bslZDwfMCSsZXi8wzrCIDhrIMYo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bslZDwfMCSsZXi8wzrCIDhrIMYo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bslZDwfMCSsZXi8wzrCIDhrIMYo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bslZDwfMCSsZXi8wzrCIDhrIMYo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/FhMccfLLUjM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/7930376740982973673/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/02/reset-identity-column-value-in-sql.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7930376740982973673?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7930376740982973673?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/FhMccfLLUjM/reset-identity-column-value-in-sql.html" title="Reset Identity Column Value in SQL Server" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/02/reset-identity-column-value-in-sql.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkMBRX8_eip7ImA9WxBVEkk.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-8666657076646981835</id><published>2010-02-15T05:27:00.000-08:00</published><updated>2010-02-15T05:27:34.142-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-15T05:27:34.142-08:00</app:edited><title>Custom Paging In GridView without objectDataSource</title><content type="html">&lt;p&gt;All we need to use the Custom paging in grid view without object data source.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Here i am going to explain my code which is used in custom paging of grid view... What you will need to do is used your DataSource SP or query with this paging...  &lt;br /&gt;
&lt;/p&gt;&lt;p&gt;All magic lies in SQL Server 2005 ROWNumber() Function.... Simple SP for this gridview datasource is  &lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;pre class="brush:sql"&gt;Select Row,ID,Name
(
    Select ROW_Number()OVER(ORDER BY ID) As Row,ID,Name 
    from table1
) AS A
Where Row=&amp;gt;@PageIndex*PageSize
and Row&amp;lt;(@PageIndex+1)*PageSize;
--here @PageIndex and @PageSize are passed as parameter as gridview1.PageIndex and gridview1.PageSize  
    &lt;/pre&gt;&lt;p&gt;if you are not familiar with RowNumber function than create one temp table use  Row as primary key with auto increament number  and than use insert select statement....  this will work in all database.....  &lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Follow is the C# code for custom gridview...I m creating new grid view control here&lt;br /&gt;
&lt;/p&gt;&lt;pre class="brush:csharp"&gt;using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Text; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls;  
namespace CustomPagingGridView 
{  
    [DefaultProperty("Text")]  
    [ToolboxData("&amp;lt;{0}:CustomePagingGrid runat=server&amp;gt;CustomePagingGrid&amp;gt;")]  
    public class CustomePagingGrid : GridView 
    {   
        public CustomePagingGrid(): base()
        {}
        
        #region Custom properties       
        // this property is to use to find the total number of record for grid         
        [Browsable(true), Category("NewDynamic")]         
        [Description("Set the virtual item count for this grid")]         
        public int VirtualItemCount         
        {             
            get
            {
                if (ViewState["pgv_vitemcount"] == null)
                    ViewState["pgv_vitemcount"] = -1;                 
                return Convert.ToInt32(ViewState["pgv_vitemcount"]);             
            }             
            set             
            {                 
                ViewState["pgv_vitemcount"] = value;             
            }         
        }         
        
        // this is used to sort the gridview columns        
        [Browsable(true), Category("NewDynamic")] [Description("Get the order by string to use for this grid when sorting event is triggered")] 
        public string OrderBy         
        {             
            get             
            {                 
                if (ViewState["pgv_orderby"] == null)                     
                    ViewState["pgv_orderby"] = string.Empty;                 
                return ViewState["pgv_orderby"].ToString();             
            }             
            protected set             
            {                 
                ViewState["pgv_orderby"] = value;             
            }         
        }            
        
        private int Index         
        {             
            get             
            {                 
                if (ViewState["pgv_index"] == null)                     
                    ViewState["pgv_index"] = 0;                 
                return Convert.ToInt32(ViewState["pgv_index"]);             
            }             
            set             
            {                 
                ViewState["pgv_index"] = value;             
            }         
        }            
        
        public int CurrentPageIndex         
        {             
            get             
            {                 
                if (ViewState["pgv_pageindex"] == null)                     
                    ViewState["pgv_pageindex"] = 0;                 
                return Convert.ToInt32(ViewState["pgv_pageindex"]);             
            }             
            set             
            {                 
                ViewState["pgv_pageindex"] = value;             
            }         
        }            
        
        private int SetCurrentIndex         
        {             
            get             
            {                 
                return CurrentPageIndex;             
            }             
            set             
            {                 
                CurrentPageIndex = value;             
            }         
        }                 
        
        
        // if this property is set to greater than zero means custom paging neede                    
        private bool CustomPaging         
        {             
            get             
            {                 
                return (VirtualItemCount != -1);             
            }         
        }          
        #endregion             
        
        #region Overriding the parent methods           
        public override object DataSource         
        {             
            get             
            {                 
                return base.DataSource;             
            }             
            set             
            {                 
                base.DataSource = value;                 
                // we store the page index here so we dont lost it in databind                 
                CurrentPageIndex = PageIndex;             
            }         
        }     
        
        protected override void OnSorting(GridViewSortEventArgs e) 
        { 
            // We store the direction for each field so that we can work out whether next sort 
            // should be asc or desc order  PageIndex = CurrentPageIndex; SortDirection direction = SortDirection.Ascending;  
            if(ViewState[e.SortExpression]!=null&amp;amp;&amp;amp; (SortDirection)ViewState[e.SortExpression] == SortDirection.Ascending)  
            {   
                direction = SortDirection.Descending; 
            }  
            ViewState[e.SortExpression] = direction;             
            OrderBy = string.Format("{0} {1}", e.SortExpression, (direction == SortDirection.Descending ? "DESC" : ""));             
            base.OnSorting(e);         
        }            
        
        protected override void InitializePager(GridViewRow row, int columnSpan, PagedDataSource pagedDataSource)         
        {             
            // This method is called to initialise the pager on the grid. We intercepted this and override             
            // the values of pagedDataSource to achieve the custom paging using the default pager supplied             
            if (CustomPaging)             
            {                 
                pagedDataSource.AllowCustomPaging = true;                 
                pagedDataSource.VirtualCount = VirtualItemCount;                 
                pagedDataSource.CurrentPageIndex = CurrentPageIndex;             
            }             
            base.InitializePager(row, columnSpan, pagedDataSource);         
        }               
        
        // here we do custom paging         
        protected override void OnPageIndexChanging(GridViewPageEventArgs e)         
        {             
            if (CustomPaging)             
            {                 
                if (this.PagerSettings.Mode == PagerButtons.NumericFirstLast || this.PagerSettings.Mode == PagerButtons.Numeric)                 
                {                     
                    base.OnPageIndexChanging(e);                 
                }                 
                else                 
                {                     
                    if (e.NewPageIndex == -1)                     
                    {                         
                        Index -= 1;                     
                    }                     
                    else if (e.NewPageIndex == 0)
                    {                         
                        Index = 0;                     
                    }                     
                    else if (e.NewPageIndex == ((int)Math.Ceiling((decimal)(VirtualItemCount) / PageSize) - 1))                     
                    {                         
                        Index = ((int)Math.Ceiling((decimal)(VirtualItemCount) / PageSize) - 1);                     
                    }                     
                    else                     
                    {                         
                        Index += 1;                     
                    }                     
                    if (Index &amp;lt; 0)                     
                    { 
                        Index = 0; 
                    }
                    CurrentPageIndex = Index;                     
                    e.NewPageIndex = Index;                     
                    base.OnPageIndexChanging(e);                 
                }             
            }         
        }           
    #endregion     
    } 
}
    &lt;/pre&gt;&lt;p&gt;if u have any doubt,please feel free to ask me....&lt;br /&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-8666657076646981835?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ayOFig-G_dghzfauQtf6g08get4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ayOFig-G_dghzfauQtf6g08get4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ayOFig-G_dghzfauQtf6g08get4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ayOFig-G_dghzfauQtf6g08get4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/M0J3idzp2uU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/8666657076646981835/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/02/custom-paging-in-gridview-without.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/8666657076646981835?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/8666657076646981835?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/M0J3idzp2uU/custom-paging-in-gridview-without.html" title="Custom Paging In GridView without objectDataSource" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/02/custom-paging-in-gridview-without.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QHSXo7cCp7ImA9WxBWGE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-5517773869066766370</id><published>2010-02-10T02:20:00.000-08:00</published><updated>2010-02-10T03:28:58.408-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T03:28:58.408-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Asp.net 3.5" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 3.5" /><title>.NET 3.5 LANGUAGE ENHANCEMENTS</title><content type="html">There are several .NET language enhancements to be introduced with Visual Studio 2008 including implicitly typed variables, extension methods, anonymous types, object initializers, collection initializers and automatic properties. These language enhancements, along with features like generics, are critical to the use of some of the new features, such as LINQ with the ADO.NET Entity Framework. What can be confusing is that these features are often referred to in the same conversation as LINQ. Because of this relation by association, you may be led to believe that these&lt;br /&gt;
features are part of LINQ. They are not; they are part of the .NET Framework 3.5 and the VB 9 and C# 3.0 languages. They are very valuable in their own rights as well as playing a huge role for LINQ. &lt;br /&gt;
&lt;br /&gt;
This article will demonstrate and discuss several key language features including:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Automatic Property setters/getters&lt;/li&gt;
&lt;li&gt;Object Initializers&lt;/li&gt;
&lt;li&gt;Collection Initializers&lt;/li&gt;
&lt;li&gt;Extension Methods&lt;/li&gt;
&lt;li&gt;Implicitly Typed Variable&lt;/li&gt;
&lt;li&gt;Anonymous Type&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_95uYHl9v39I/S3KDjEIvQuI/AAAAAAAAAIo/0RYheA2q53E/s1600-h/typecast.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="384" src="http://4.bp.blogspot.com/_95uYHl9v39I/S3KDjEIvQuI/AAAAAAAAAIo/0RYheA2q53E/s640/typecast.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Automatic Properties &lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Since creating classes by hand can be monotonous at times, developers use either code generation programs and IDE Add-Ins to assist in creating classes and their properties. Creating properties can be a very redundant process, especially when there is no logic in the getters and setters other than getting and setting the value of the private field. Using public fields would reduce the code required, however public fields do have some drawbacks as they are not supported by some other features such as inherent data binding.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;public class Customer
{
private int _customerID;
private string _companyName;
private Address _businessAddress;
private string _phone;
public int CustomerID
{
get { return _customerID; }
set { _customerID = value; }
}
public string CompanyName
{
get { return _companyName; }
set { _companyName = value; }
}
public Address BusinessAddress
{
get { return _businessAddress; }
set { _businessAddress = value; }
}
public string Phone
{
get { return _phone; }
set { _phone = value; }
}
}
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
how the same result can be achieved through automatic properties with less code than&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;public class Customer
{
public int CustomerID { get; set; }
public string CompanyName { get; set; }
public Address BusinessAddress { get; set; }
public string Phone { get; set; }
}
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Object Initializers&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
It is often helpful to have a constructor that accepts the key information that can be used to initialize an object. Many code refactoring tools help create constructors like this with .NET 2. However another new feature coming with .NET 3.5, C# 3 and VB 9 is object initialization. Object Initializers allow you to pass in named values for each of the public properties that will then be used to initialize the object.&lt;br /&gt;
&lt;br /&gt;
For example, initializing an instance of the Customer class could be accomplished using the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;Customer customer = new Customer();
customer.CustomerID = 101;
customer.CompanyName = "Foo Company";
customer.BusinessAddress = new Address();
customer.Phone = "555-555-1212";
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
However, by taking advantage of Object Initializers an instance of the Customer class can be created using the following syntax:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;Customer customer = new Customer {
CustomerID = 101,
CompanyName = "Foo Company",
BusinessAddress = new Address(),
Phone = "555-555-1212" };
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
The syntax is to wrap the named parameters and their values with curly braces. Object Initializers allow you to pass in any named public property to the constructor of the class. This is a great feature as it removes the need to create multiple overloaded constructors using different parameter lists to achieve the same goal. While you can currently create your own constructors, Object initializers are nice because you do not have to create multiple overloaded constructors to handle the various combinations of how you might want to initialize the object. To make matters easier, when typing the named parameters the intellisense feature of the IDE will display a list of the named parameters for you. You do not have to pass all of the parameters in and in fact, you can even use a nested object initialize for the BusinessAddress parameter, as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;Customer customer = new Customer
{
CustomerID = 101,
CompanyName = "Foo Company",
BusinessAddress = new Address { City="Somewhere", State="FL" },
Phone = "555-555-1212"
};
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Collection Initializers&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Initializing collections have always been a bother to me. I never enjoy having to create the collection first and then add the items one by one to the collection in separate statements. (What can I say, I like tidy code.) Like Object Initializers, the new Collection Initializers allow you to create a collection and initialize it with a series of objects in a single statement. The following statement demonstrates how the syntax is very similar to that of the Object Initializers. Initializing a List&lt;customer&gt; is accomplished by passing the instances of the Customer objects wrapped inside of curly braces.&amp;nbsp;&lt;/customer&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;List&lt;customer&gt; custList = new List&lt;customer&gt; 
{ customer1, customer2, customer3 };
&lt;/customer&gt;&lt;/customer&gt;
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
Collection Initializers can also be combined with Object Initializers. The result is a slick piece of code that initializes both the objects and the collection in a single statement.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;List&lt;customer&gt; custList = new List&lt;customer&gt;
{
new Customer {ID = 101, CompanyName = "Foo Company"},
new Customer {ID = 102, CompanyName = "Goo Company"},
new Customer {ID = 103, CompanyName = "Hoo Company"}
};
&lt;/customer&gt;&lt;/customer&gt;
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
The List&lt;customer&gt; and its 3 Customers from this example could also be written without Object Initializers nor Collection Initializers, in several lines of code. The syntax for that could look something like this without&amp;nbsp; using these new features:&lt;/customer&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;Customer customerFoo = new Customer();
customerFoo.ID = 101;
customerFoo.CompanyName = "Foo Company";
Customer customerGoo = new Customer();
customerGoo.ID = 102;
customerGoo.CompanyName = "Goo Company";
Customer customerHoo = new Customer();
customerHoo.ID = 103;
customerHoo.CompanyName = "Hoo Company";
List&lt;customer&gt; customerList3 = new List&lt;customer&gt;();
customerList3.Add(customerFoo);
customerList3.Add(customerGoo);
customerList3.Add(customerHoo);
&lt;/customer&gt;&lt;/customer&gt;
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Extension Methods&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Have you ever looked through the list of intellisense for an object hoping to find a method that handles your specific need only to find that it did not exist? One way you can handle this is to use a new feature called Extension Methods. Extension methods are a new feature that allows you to enhance an existing class by adding a new method to it without modifying the actual code for the class. This is especially useful when using LINQ because several extension methods are available in writing LINQ query expressions.&lt;br /&gt;
&lt;br /&gt;
For example, imagine that you want to cube a number. You might have the length of one side of a cube and you want to know its volume. Since all the sides are the same length, it would be nice to simply have a method that calculates the cube of an integer. You might start by looking at the System.Int32 class to see if it exposes a Cube method, only to find that it does not. One solution for this is to create an extension method for the int class that calculates the Cube of an integer. Extension Methods must be created in a static class and the Extension Method itself must be defined as static. The syntax is pretty straightforward and familiar, except for the this keyword that is passed as the first parameter to the Extension Method. Notice in the code below that I create a static method named Cube that accepts a single parameter. In a static method, preceding the first parameter with the this keyword creates an extension method that applies to the type of that parameter. So in this case, I added an Extension Method called Cube to the int type.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;public static class MyExtensions
{
public static int Cube(this int someNumber)
{
return someNumber ^ 3;
}
}
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
When you create an Extension Method, the method sows up in the intellisense in the IDE, as well. With this new code I can calculate the cube of an integer using the following code sample:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;int oneSide = 3;
int theCube = oneSide.Cube(); // Returns 27
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
As nice as this feature is I do not recommend creating Extension Methods on classes if instead you can create a method for the class yourself. For example, if you wanted to create a method to operate on a Customer class to calculate their credit limit, best practices would be to add this method to the Customer class itself. Creating an Extension method in this case would violate the encapsulation principle by placing the code for the Customer’s credit limit calculation outside of the Customer class.&lt;br /&gt;
&lt;br /&gt;
However, Extension Methods are very useful when you cannot add a method to the class itself, as in the case of creating a Cube method on the int class. Just because you can use a tool, does not mean you should use a tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Anonymous Types and Implicitly Typed Variables&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
When using LINQ to write query expressions, you might want to return information from several classes. It is very likely that you'd only want to return a small set of properties from these classes. However, when you retrieve information from different class sources in this manner, you cannot retrieve a generic list of your class type because you are not retrieving a specific class type. This is where Anonymous Types step in and make things easier because Anonymous Types allow you to create a class structure on the fly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;var dog = new { Breed = "Cocker Spaniel",
Coat = "black", FerocityLevel = 1 };
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
Notice that the code above creates a new instance of a class that describes a dog. The dog variable will now represent the instance of the class and it will expose the Breed, Coat and Ferocity properties. Using this code I was able to create a structure for my data without having to create a Dog class explicitly. While I would rarely create a class using this feature to represent a Dog, this feature does come in handy when used with LINQ.&lt;br /&gt;
&lt;br /&gt;
When you create an Anonymous Type you need to declare a variable to refer to the object. Since you do not know what type you will be getting (since it is a new and anonymous type), you can declare the variable with the var keyword. This technique is called using an Implicitly Typed Variable. When writing a LINQ query expression, you may return various pieces of information. You could return all of these data bits and create an Anonymous Type to store them. For example, let’s assume you have a List&lt;customer&gt; and each Customer has a BusinessAddress property of type Address. In this situation you want to return the CompanyName and the State where the company is located. One way to accomplish this using an Anonymous Type is shown in below.&amp;nbsp;&lt;/customer&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush:csharp"&gt;List&lt;customer&gt; customerList = new List&lt;customer&gt;
{
new Customer {ID = 101,
CompanyName = "Foo Co",
BusinessAddress = new Address {State="FL"}},
new Customer {ID = 102,
CompanyName = "Goo Co",
BusinessAddress = new Address {State="NY"}},
new Customer {ID = 103,
CompanyName = "Hoo Co",
BusinessAddress = new Address {State="NY"}},
new Customer {ID = 104,
CompanyName = "Koo Co",
BusinessAddress = new Address {State="NY"}}
};
var query = from c in customerList
where c.BusinessAddress.State.Equals("FL")
select new { Name = c.CompanyName,
c.BusinessAddress.State };
foreach (var co in query)
Console.WriteLine(co.Name + " - " + co.State);
&lt;/customer&gt;&lt;/customer&gt;
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
Pay particular attention to the select clause in the LINQ query expression. The select clause is creating an instance of an Anonymous Type that will have a Name and a State property. These values come from 2 different objects, the Customer and the Address. Also notice that the properties can be explicitly renamed (CompanyName is renamed to Name) or they can implicitly take on the name as happens with the State property. Anonymous Types are very useful when retrieving data with LINQ.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;&amp;nbsp;Summary&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
There are a lot of new language features coming with .NET 3.5 that both add new functionality and make the using of existing technologies easier. As we have seen in the past, when new technologies have been introduced, such as with generics, they often are the precursors to other technologies. The introduction of Generics allowed us to create strongly typed lists. Now because of those strongly typed lists of objects we will be able to write LINQ query expressions against the strongly typed objects and access their properties explicitly even using intellisense. These new features such as Object Initializers and Anonymous Types are the building blocks of LINQ and other future .NET technologies.&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-5517773869066766370?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zW-mVIgWR0X1x1sHe0pbPpHypig/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zW-mVIgWR0X1x1sHe0pbPpHypig/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zW-mVIgWR0X1x1sHe0pbPpHypig/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zW-mVIgWR0X1x1sHe0pbPpHypig/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/BTPyLJVX3_Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/5517773869066766370/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/02/net-35-language-enhancements.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/5517773869066766370?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/5517773869066766370?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/BTPyLJVX3_Q/net-35-language-enhancements.html" title=".NET 3.5 LANGUAGE ENHANCEMENTS" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_95uYHl9v39I/S3KDjEIvQuI/AAAAAAAAAIo/0RYheA2q53E/s72-c/typecast.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/02/net-35-language-enhancements.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEYNQH04fip7ImA9WxBWGE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-8670699591029876521</id><published>2010-02-06T02:38:00.000-08:00</published><updated>2010-02-10T03:43:11.336-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T03:43:11.336-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Sql server 2008" /><title>NEW DATA TYPES IN SQL SERVER 2008</title><content type="html">&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;We will take&lt;br /&gt;
        a look at the following new data types, each of which is available in all editions&lt;br /&gt;
        of &lt;b&gt;SQL Server 2008:&lt;/b&gt; • &lt;b&gt;Date and Time: &lt;/b&gt;Four new date and time data types&lt;br /&gt;
        have been added, making working with time much easier than it ever has in the past.&lt;br /&gt;
        They include: DATE, TIME, DATETIME2, and DATETIMEOFFSET.&lt;/span&gt; &lt;span style="font-size: small;"&gt;&lt;br /&gt;
            • &lt;b&gt;Spatial: &lt;/b&gt;Two new spatial data types have been added--GEOMETRY and GEOGRAPHY--&lt;br /&gt;
            which you can use to natively store and manipulate location-based information, such&lt;br /&gt;
            as Global Positioning System (GPS) data.&lt;/span&gt; &lt;span style="font-size: small;"&gt;• &lt;b&gt;&lt;br /&gt;
                HIERARCHYID:&lt;/b&gt; The HIERARCHYID data type is used to enable database applications&lt;br /&gt;
                to model hierarchical tree structures, such as the organization chart of a business.&lt;/span&gt;&lt;br /&gt;
    &lt;span style="font-size: small;"&gt;• &lt;b&gt;FILESTREAM:&lt;/b&gt; FILESTREAM is not a data type as&lt;br /&gt;
        such, but is a variation of the VARBINARY(MAX) data type that allows unstructured&lt;br /&gt;
        data to be stored in the file system instead of inside the SQL Server database.&lt;br /&gt;
        Because this option requires a lot of involvement from both the DBA administration&lt;br /&gt;
        and development side, I will spend more time on this topic than the rest. &lt;/span&gt;&lt;br /&gt;
    &lt;span style="font-size: large;"&gt;&lt;b&gt;Date and Time&lt;/b&gt;&lt;/span&gt; &lt;span style="font-size: small;"&gt;&lt;br /&gt;
        In SQL Server 2005 and earlier, SQL Server only offered two date and time data types:&lt;br /&gt;
        DATETIME and SMALLDATETIME. While they were useful in many cases, they had a lot&lt;br /&gt;
        of limitations, including:&lt;/span&gt;&lt;br /&gt;
    &lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;        &lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;/div&gt;    &lt;div style="font-family: Arial,Helvetica,sans-serif; text-align: justify;"&gt;        &lt;ul&gt;            &lt;li&gt;&lt;span style="font-family: inherit; font-size: small;"&gt;Both the date value and the&lt;br /&gt;
                time value are part of both of these data types, and you can’t choose to store one&lt;br /&gt;
                or the other. This can cause several problems:&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-family: inherit; font-size: small;"&gt;It often causes a lot of wasted&lt;br /&gt;
                storage because you store data you don’t need or want.&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-family: inherit; font-size: small;"&gt;It adds unwanted complexity&lt;br /&gt;
                to many queries because the data types often have to be converted to a different&lt;br /&gt;
                form to be useful.&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-family: inherit; font-size: small;"&gt;It often reduces performance&lt;br /&gt;
                because WHERE clauses with these data and time data types&amp;nbsp; often have to include&lt;br /&gt;
                functions to convert them to a more useful form, preventing these queries from using&lt;br /&gt;
                indexes.&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-family: inherit; font-size: small;"&gt;They are not time-zone aware,&lt;br /&gt;
                which requires extra coding for time-aware applications.&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-family: inherit; font-size: small;"&gt;Precision is only .333 seconds,&lt;br /&gt;
                which is not granular enough for some applications.&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-family: inherit; font-size: small;"&gt;The range of supported dates&lt;br /&gt;
                is not adequate for some applications, and the range does not match the range of&lt;br /&gt;
                the .NET CLR DATETIME data type, which requires additional conversion code.&lt;/span&gt;&lt;/li&gt;
        &lt;/ul&gt;    &lt;/div&gt;    &lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
        To overcome these problems, SQL Server 2008 introduces four new date and time data&lt;br /&gt;
        types, &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;described in the&lt;br /&gt;
            following sections. All of these new date and time data types work with SQL Server&lt;br /&gt;
        &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;2008 date and time functions,&lt;br /&gt;
            which have been enhanced in order to properly understand the new&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                In addition, some new date and time functions have been added to take advantage&lt;br /&gt;
                of the &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;capabilities of&lt;br /&gt;
                    these new data types. The new functions include SYSDATETIME, &lt;/span&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;TODATETIMEOFFSET, SYSUTCDATETIME,&lt;br /&gt;
            and&lt;/span&gt; DATE.&lt;/span&gt; &lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                As you can imagine, the DATE data type only stores a date in the format of YYYY-MM-DD.&lt;br /&gt;
                It has&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;a range of 0001-01-01 through&lt;br /&gt;
                    9999-12-32, which should be adequate for most business and&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;scientific applications. The&lt;br /&gt;
                    accuracy is 1 day, and it only takes 3 bytes to store the date.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;span style="font-size: small;"&gt;&lt;br /&gt;
        &lt;br /&gt;&lt;br /&gt;
        &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;pre class="brush:sql"&gt;        --Sample DATE output
        DECLARE @datevariable as DATE            
        SET @datevariable = getdate()            
        PRINT @datevariable
        Result: 2008-08-15        
        &lt;/pre&gt;        &lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;TIME&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;span style="font-size: small;"&gt;&lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
        &amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;TIME is stored in the format:&lt;br /&gt;
            hh:mm:ss.nnnnnnn, with a range of 00:00:00.0000000 through&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;23:59:59:9999999 and is accurate&lt;br /&gt;
            to 100 nanoseconds. Storage depends on the precision and scale &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                selected, and runs from 3 to 5 bytes.&lt;/span&gt;&lt;/span&gt; &lt;span style="font-size: small;"&gt;&lt;br /&gt;
                    &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                    &lt;pre class="brush:sql"&gt;                    --Sample TIME output                        
                    DECLARE @timevariable as TIME
                    SET @timevariable = getdate()                       
                    PRINT @timevariable                        
                    Result: 14:26:52.3100000
                    &lt;/pre&gt;                    &lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;DATETIME2&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;span style="font-size: small;"&gt;&lt;br /&gt;
        &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;DATETIME2 is very similar to&lt;br /&gt;
            the older DATETIME data type, but has a greater range and&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;precision. The format is YYYY-MM-DD&lt;br /&gt;
            hh:mm:ss:nnnnnnnm with a range of 0001-01-01&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;00:00:00.0000000 through 9999-12-31&lt;br /&gt;
            23:59:59.9999999, with an accuracy of 100 nanoseconds.&lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                depends on the precision and scale selected, and runs from 6 to 8 bytes.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;span style="font-size: small;"&gt;&lt;br /&gt;
        &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;pre class="brush:sql"&gt;        --Sample DATETIME2 output with a precision of 7
        DECLARE @datetime2variable datetime2(7)
        SET @datetime2variable = Getdate()
        PRINT @datetime2variable
        Result: 2008-08-15 14:27:51.5300000
        &lt;/pre&gt;        &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;DATETIMEOFFSET&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;span style="font-size: small;"&gt;&lt;br /&gt;
        &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;DATETIMEOFFSET is similar to&lt;br /&gt;
            DATETIME2, but includes additional information to track the&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;time zone. The format is YYYY-MM-DD&lt;br /&gt;
            hh:mm:ss[.nnnnnnn] [+|-]hh:mm with a range of 0001-&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;01-01 00:00:00.0000000 through&lt;br /&gt;
            0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999. &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Universal Time (UTC), with an accuracy of 100 nanoseconds. Storage depends on the&lt;br /&gt;
            &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;and scale selected, and&lt;br /&gt;
                runs from 8 to 10 bytes.&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                    zone aware means a time zone identifier is stored as a part of DATETIMEOFFSET column.&lt;br /&gt;
                &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;time zone identification&lt;br /&gt;
                    is represented by a [-|+] hh:mm designation. A valid time zone falls in&lt;/span&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;range of -14:00 to +14:00, and&lt;br /&gt;
            this value is added or subtracted from UTC to obtain the local&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
        &amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;--Sample DATETIMEOFFSET&lt;br /&gt;
            output with a precision of 0&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
        &lt;pre class="brush:sql"&gt;        --Specify a date, time, and time zone
        DECLARE @datetimeoffsetvariable DATETIMEOFFSET(0)
        SET @datetimeoffsetvariable ='2008-10-03 09:00:00 -10:00'
        --Specify a different date, time and time zone
        
        DECLARE @datetimeoffsetvariable1 DATETIMEOFFSET(0)
        SET @datetimeoffsetvariable1= '2008-10-04 18:00:00 +0:00'
        
        --Find the difference in hours between the above dates, times,and timezones
        SELECT DATEDIFF(hh,@datetimeoffsetvariable,@datetimeoffsetvariable1)                    
        
        Result: 23
        &lt;/pre&gt;                &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                &lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                    Spatial&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; &lt;span style="font-size: small;"&gt;&lt;span style="font-size: large;"&gt;&lt;br /&gt;
                        &lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span
                            style="font-family: Arial,Helvetica,sans-serif;"&gt;While spatial data has been stored&lt;br /&gt;
                            in many SQL Server databases for many years (using conventional &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                                data types), SQL Server 2008 introduces two specific spatial data types that can&lt;br /&gt;
                                make it easier for&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;developers&lt;br /&gt;
                                    to integrate spatial data in their SQL Server-based applications. In addition, by&lt;br /&gt;
                                    storing&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;spatial data in&lt;br /&gt;
                                        relational tables, it becomes much easier to combine spatial data with other kinds&lt;br /&gt;
                                        of&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;business data. For&lt;br /&gt;
                                            example, by combining spatial data (such as longitude and latitude) with the&lt;br /&gt;
&lt;br /&gt;
                                            &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;physical address of a&lt;br /&gt;
                        business, applications can be created to map business locations on a map.&lt;/span&gt;&lt;br
                            style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                    &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;The two new spatial data types&lt;br /&gt;
                        in SQL 2008 are:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;br /&gt;&lt;br /&gt;
                            &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;• &lt;b&gt;GEOMETRY&lt;/b&gt;: Used to store&lt;br /&gt;
                                planar (flat-earth) data. It is generally used to store XY&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;coordinates that represent points,&lt;br /&gt;
                                lines, and polygons in a two-dimensional space. For example&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;storing XY coordinates in the&lt;br /&gt;
                                GEOMETRY data type can be used to map the exterior of a&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;building.&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;• &lt;b&gt;GEOGRAPHY&lt;/b&gt;: Used to store&lt;br /&gt;
                                ellipsoidal (round-earth) data. It is used to store latitude and&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;longitude coordinates that represent&lt;br /&gt;
                                points, lines, and polygons on the earth’s surface. For&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;example, GPS data that represents&lt;br /&gt;
                                the lay of the land is one example of data that can be stored&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;in the GEOGRAPHY data type.&lt;/span&gt;&lt;br
                                style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;b&gt;GEOMETRY &lt;/b&gt;and &lt;b&gt;GEOGRAPHY&lt;br /&gt;
                            &lt;/b&gt;data types are implemented as .NET CLR data types. This means &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                                that they can support various properties and methods specific to the data. For example,&lt;br /&gt;
                                a method&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;can be used to&lt;br /&gt;
                                    calculate the distance between two GEOMETRY XY coordinates, or the distance&lt;/span&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;between two GEOGRAPHY latitude&lt;br /&gt;
                                and longitude coordinates. Another example is a method to see&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                                    if two spatial objects intersect or not. Methods defined by the Open Geospatial&lt;br /&gt;
                                    Consortium &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;standard, and&lt;br /&gt;
                                        Microsoft extensions to that standard, can be used. To take full advantage of these&lt;/span&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;methods, you will have to be&lt;br /&gt;
                                an expert in spatial data.&lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;Another&lt;br /&gt;
                                    feature of spatial data types is that they support special spatial indexes. Unlike&lt;br /&gt;
                                    conventional&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;indexes,&lt;br /&gt;
                                        spatial indexes consist of a grid-based hierarchy in which each level of the index&lt;br /&gt;
                                        subdivides&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;the grid sector that is defined&lt;br /&gt;
                                in the level above. But like conventional indexes, the SQL Server query &lt;/span&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;optimizer can use spatial indexes&lt;br /&gt;
                                to speed up the performance of queries that return spatial data.&lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;Spatial&lt;br /&gt;
                                    data is an area unfamiliar to many DBAs. If this is a topic you want to learn more&lt;br /&gt;
                                    about, you&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;will need a&lt;br /&gt;
                                        good math background, otherwise you will get lost very quickly.&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;
                                &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                                &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;HIERARCHYID&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br
                                    style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;While hierarchical tree structures&lt;br /&gt;
                                are commonly used in many applications, SQL Server has, up to &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                                    not made it easy to represent and store them in relational tables. In SQL Server&lt;br /&gt;
                                    2008, the&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;b&gt;HIERARCHYID&lt;/b&gt; data type&lt;br /&gt;
                                has been added to help resolve this problem. It is designed to store &lt;/span&gt;&lt;br /&gt;
                            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;that represent the position of&lt;br /&gt;
                                nodes in a hierarchal tree structure.&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                                    For example, the HIERARCHYID data type makes it easier to express the following&lt;br /&gt;
                                    types of&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;relationships&lt;br /&gt;
                                        without requiring multiple parent/child tables and complex joins:&lt;/span&gt;&lt;br /&gt;
        &lt;ul&gt;            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Organizational structures&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                A set of tasks that make up a larger projects (like a GANTT chart)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                File systems (folders and their sub-folders)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                A classification of language terms&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                A bill of materials to assemble or build a product&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                A graphical representation of links between web pages&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
        &lt;/ul&gt;        &lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
            Unlike standard data types, the &lt;b&gt;HIERARCHYID &lt;/b&gt;data type is a CLR user-defined&lt;br /&gt;
            type, and it exposes &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;many&lt;br /&gt;
                methods that allow you to manipulate the date stored within it. For example, there&lt;br /&gt;
                are methods&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;to get the&lt;br /&gt;
                    current hierarchy level, get the previous level, get the next level, and many more.&lt;br /&gt;
                    In fact,&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;the HIERARCHYID&lt;br /&gt;
                        data type is only used to store hierarchical data; it does not automatically&lt;br /&gt;
            &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;represent a hierarchical&lt;br /&gt;
                structure. It is the responsibility of the application to create and assign&lt;/span&gt;&lt;br /&gt;
            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;HIERARCHYID values in a way that&lt;br /&gt;
                represents the desired relationship. Think of a &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                    HIERARCHYID data type as a place to store positional nodes of a tree structure,&lt;br /&gt;
                    not as a way to &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;create&lt;br /&gt;
                        the tree structure.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;br /&gt;&lt;br /&gt;
            &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
            &lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                FILESTREAM&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;SQL Server is great for storing&lt;br /&gt;
                relational data in a highly structured format, but it has never been &lt;/span&gt;&lt;br /&gt;
            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;particularly good at storing&lt;br /&gt;
                unstructured data, such as videos, graphic files, Word documents, Excel&lt;/span&gt;&lt;br /&gt;
            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;spreadsheets, and so on. In the&lt;br /&gt;
                past, when developers wanted to use SQL Server to manage such&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                    unstructured data, they essentially had two choices:&lt;/span&gt;&lt;br /&gt;
        &lt;ul&gt;            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Store it in VARBINARY(MAX) columns inside the database&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Store the data outside of the database as part of the file system, and include pointers&lt;br /&gt;
                inside &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;a column that pointed&lt;br /&gt;
                    to the file’s location. This allowed an application that needed access &lt;/span&gt;&lt;br /&gt;
                &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;to the file to find it by looking&lt;br /&gt;
                    up the file’s location from inside a SQL Server table.Neither of these options was&lt;br /&gt;
                    perfect. Storing unstructured data in VARBINARY(MAX) columns&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                        offers less than ideal performance, has a 2 GB size limit, and can dramatically&lt;br /&gt;
                        increase the size of a&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                            database. Likewise, storing unstructured data in the file system requires the DBA&lt;br /&gt;
                            to overcome several&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;difficulties.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
        &lt;/ul&gt;        &lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
            For example:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
        &lt;ul&gt;            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Files have a unique naming system that allows hundreds, if not thousands of files&lt;br /&gt;
                to be keep &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;track of and&lt;br /&gt;
                    requires very careful management of the folders to store the data.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Security is a problem and often requires using NTFS permissions to keep people from&lt;br /&gt;
                accessing the files inappropriately.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                The DBA has to perform separate backups of the database and the files&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Problems can occur when outside files are modified or moved and the database is&lt;br /&gt;
                not updated&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;to reflect&lt;br /&gt;
                    this.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
        &lt;/ul&gt;        &lt;span style="font-size: small;"&gt;&lt;br /&gt;
            &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;To help resolve these problems,&lt;br /&gt;
                SQL Server 2008 has introduced what is called &lt;b&gt;FILESTREAM &lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                    storage, essentially a hybrid approach that combines the best features of the previous&lt;br /&gt;
                    two options.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;br /&gt;&lt;br /&gt;
                        &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                        &lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;Benefits of FILESTREAM&lt;/span&gt;&lt;/b&gt;&lt;br
                            style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
                        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;b&gt;FILESTREAM &lt;/b&gt;storage is&lt;br /&gt;
                            implemented in SQL Server 2008 by storing VARBINARY(MAX) binary &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                                large objects (BLOBs) outside of the database and in the NTFS file system. While&lt;br /&gt;
                                this sounds very&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;similar&lt;br /&gt;
                                    to the older method of storing unstructured data in the file system and pointing&lt;br /&gt;
                                    to it from a&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;column, it&lt;br /&gt;
                                        is much more sophisticated. Instead of a simple link from a column to an outside&lt;br /&gt;
                                        file, the&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;SQL Server Database&lt;br /&gt;
                                            Engine has been integrated with the NTFS file system for optimum&lt;br /&gt;
                        &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;performance and ease of&lt;br /&gt;
                            administration. For example, &lt;b&gt;FILESTREAM &lt;/b&gt;data uses the Windows OS&lt;/span&gt;&lt;br /&gt;
                        &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;system cache for caching data&lt;br /&gt;
                            instead of the SQL Server buffer pool. This allows SQL Server to do&lt;/span&gt; &lt;span
                                style="font-family: Arial,Helvetica,sans-serif;"&gt;what it does best: manage structured&lt;br /&gt;
                                data, and allows the Windows OS to do what is does best:&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                                    manage large files. In addition, SQL Server handles all of the links between database&lt;br /&gt;
                                    columns and&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;the files,&lt;br /&gt;
                                        so we don’t have to. &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;In&lt;br /&gt;
                                            addition, &lt;b&gt;FILESTREAM &lt;/b&gt;storage offers these additional benefits:&lt;/span&gt;&lt;br /&gt;
        &lt;ul&gt;            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Transact-SQL can be used to SELECT, INSERT, UPDATE, DELETE FILESTREAM data.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                By default, FILESTREAM data is backed up and restored as part of the database file.&lt;br /&gt;
                If you want, there is an option available so you can backup a database without the&lt;br /&gt;
                FILESTREAM data.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                The size of the stored data is only limited by the available space of the file system.&lt;br /&gt;
                Standard&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;VARBINARY(MAX)&lt;br /&gt;
                    data is limited to 2 GB.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
        &lt;/ul&gt;        &lt;span style="font-size: small;"&gt;&lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
            Limitations of FILESTREAM&lt;/span&gt;&lt;/b&gt;&lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
            &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;As you might expect, using FILESTREAM&lt;br /&gt;
                storage is not right for every situation. For example, it is&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                    best used under the following conditions:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
        &lt;ul&gt;            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                When the BLOB file sizes average 1MB or higher.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                When fast read access is important to your application.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                When applications are being built that use a middle layer for application logic.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                When encryption is not required, as it is not supported for FILESTREAM data.&lt;/span&gt;&lt;br /&gt;
                &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;If your application doesn’t meet&lt;br /&gt;
                    the above conditions, then using the standard VARBINARY(MAX) data type might be&lt;br /&gt;
                    your best option. &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;If you&lt;br /&gt;
                        are used to storing binary data inside your database, or outside your database (but&lt;br /&gt;
                        using&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;pointers inside&lt;br /&gt;
                            the database that point to the binary files), then you will find using FILESTREAM&lt;/span&gt;&lt;br /&gt;
                &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;storage to be substantially different.&lt;br /&gt;
                    You will want to thoroughly test your options before &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                        implementing one option or the other, in any new applications you build.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
        &lt;/ul&gt;        &lt;span style="font-size: small;"&gt;&lt;b&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
        &lt;/span&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;How to Implement FILESTREAM&lt;br /&gt;
            Storage&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;Enabling SQL Server&lt;br /&gt;
                to use FILESTREAM data is a multiple-step process, which includes:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
        &lt;ul&gt;            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Enabling the SQL Server instance to use FILESTREAM data&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Enabling a SQL Server database to use FILESTREAM data&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
                Creating FILESTREAM-enabled columns in a table, by specifying the "VARBINARY(MAX)&lt;br /&gt;
                FILESTREAM" data type.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
        &lt;/ul&gt;        &lt;span style="font-size: small;"&gt;&lt;br /&gt;
            &lt;br style="font-family: Arial,Helvetica,sans-serif;" /&gt;&lt;br /&gt;
        &lt;/span&gt;&lt;br /&gt;
&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-8670699591029876521?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/m2v02uwHgBG13gXaqf0B-84QXGo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/m2v02uwHgBG13gXaqf0B-84QXGo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/m2v02uwHgBG13gXaqf0B-84QXGo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/m2v02uwHgBG13gXaqf0B-84QXGo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/T1nUPukxWOU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/8670699591029876521/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/02/new-data-types-in-sql-server-2008.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/8670699591029876521?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/8670699591029876521?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/T1nUPukxWOU/new-data-types-in-sql-server-2008.html" title="NEW DATA TYPES IN SQL SERVER 2008" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/02/new-data-types-in-sql-server-2008.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMFR3s4cCp7ImA9WxBWGE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-4389892901161218302</id><published>2010-02-04T03:37:00.000-08:00</published><updated>2010-02-10T03:46:56.538-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T03:46:56.538-08:00</app:edited><title>Base Page For Detecting Session Timeout in ASP.Net/C#</title><content type="html">In this tutorial we will be going over how to create a base page   class  to handle your sessions. The number one question I get asked time  and  time again is how to manage sessions, and how to detect if a  session has  expired. Back in the days before .Net things were a little  more  complicated when it came to solving this riddle, but with the  advent of  the .Net Framework 2.0 a new class was introduced, the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.aspx" rel="nofollow external" title="External link"&gt;HttpSessionState   Class&lt;/a&gt;, which is a member of the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.sessionstate.aspx" rel="nofollow external" title="External link"&gt;System.Web.SessionState   Namespace&lt;/a&gt;. The new &lt;b&gt;HttpSessionState&lt;/b&gt; Class gives  us access to session state items and other lifetime  management methods.&lt;br /&gt;
&lt;br /&gt;
One of the items in the &lt;b&gt;HttpSessionState&lt;/b&gt; class we  will be looking at is the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.isnewsession.aspx" rel="nofollow 
external" title="External link"&gt;IsNewSession   Property&lt;/a&gt;. This property lets us know whether the current session   was created wtih the current request, or if it was an existing session.   This is invaluable as we can use it to determine if the users session   had expired or timed out. The &lt;b&gt;IsNewSession&lt;/b&gt; Property is  more robust and advanced then simply checking if the session  is null  because it takes into account a session timeout as well.&lt;br /&gt;
&lt;br /&gt;
In  this tutorial we will create a base page class that we can inherit  all  our pages from, and in this class we will check the status of the  users  session in the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.page.oninit.aspx" rel="nofollow external" title="External link"&gt;Page.OnInit   Method&lt;/a&gt;. The &lt;b&gt;OnOnit&lt;/b&gt; Method fires before  the Page  Load Event, giving us the ability to check the session before  the page  is actually rendered. So lets get to some code.&lt;br /&gt;
&lt;br /&gt;
The first thing  we will need to do, as with any class you create, is to  make sure we  have a reference to the appropriate Namespaces. For our  class we need  but 2 Namespaces, the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.aspx" rel="nofollow external" title="External link"&gt;System.Web.UI   Namespace&lt;/a&gt; and the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.aspx" rel="nofollow external" title="External link"&gt;System   Namespace&lt;/a&gt;, so lets add them to our class.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;NOTE:&lt;/b&gt;  All Namespace references need to come  before the declaration of your  class.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;using System;
using System.Web.UI;&lt;/pre&gt;&lt;br /&gt;
Now we are going to declare our class, the class in this example is   named &lt;b&gt;SessionCheck&lt;/b&gt;, and it looks like&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;public class SessionCheck: System.Web.UI.Page
{

}
&lt;/pre&gt;&lt;br /&gt;
&lt;pre&gt;You will notice that our base class, which we will be inheriting from, inherits from the System.Web.UI.Page class. Doing this gives us access to all the methods, properties and events of the Page  class. In our base class we will have a single property, this will be the property that will hold the URL we want the user to redirect to if there is a problem with their session. We make this property static  so we can access it without having to create an instance of the class. We dont want to have to do this because we are inheriting from it. 
This is our property


&lt;pre class="brush:csharp"&gt;/// &lt;summary&gt;
/// property vcariable for the URL Property
/// &lt;/summary&gt;
private static string _url;

/// &lt;summary&gt;
/// property to hold the redirect url we will
/// use if the users session is expired or has
/// timed out.
/// &lt;/summary&gt;
public static string URL
{
    get { return _url; }
    set { _url = value; }
}&lt;/pre&gt;Now that we have our property out of the way, we will look at the only  of our base class, the &lt;b&gt;OnInit&lt;/b&gt; which we will override in order to add our ow functionality. In 
this method we will also initialize our base class, you do that with line


&lt;pre&gt;base.OnInit(e);&lt;/pre&gt;In our &lt;b&gt;OnInit&lt;/b&gt; Method we will first check to
 see if the current session is null. If the session is null we then will
 check the &lt;b&gt;IsNewSession&lt;/b&gt; Property to see if 
this session was created in this request. If we determine the session is
 a new session, we will then cal upon the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httprequest.headers.aspx" rel="nofollow external" title="External link"&gt;Headers 
Property&lt;/a&gt; of the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httprequest.aspx" rel="nofollow external" title="External link"&gt;HttpRequest
 Class&lt;/a&gt;, which is located in the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.aspx" rel="nofollow external" title="External link"&gt;System.Web
 Namespace&lt;/a&gt;.



In our &lt;b&gt;OnInit&lt;/b&gt; Method we will first check to
 see if the current session is null. If the session is null we then will
 check the &lt;b&gt;IsNewSession&lt;/b&gt; Property to see if 
this session was created in this request. If we determine the session is
 a new session, we will then cal upon the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httprequest.headers.aspx" rel="nofollow external" title="External link"&gt;Headers 
Property&lt;/a&gt; of the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httprequest.aspx" rel="nofollow external" title="External link"&gt;HttpRequest
 Class&lt;/a&gt;, which is located in the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.aspx" rel="nofollow external" title="External link"&gt;System.Web
 Namespace&lt;/a&gt;.



The &lt;b&gt;Header&lt;/b&gt; we are retrieving is the &lt;b&gt;Cookie&lt;/b&gt; Header. Once we have this, we will first 
check to see if it's null, if it's not null we will look for the value &lt;b&gt;ASP.Net_SessionId&lt;/b&gt;. Now if we make it this far, and
 that cookie exists, we know the session has timed out, so we will then 
redirect the user to our redirect page, which is set with the &lt;b&gt;URL&lt;/b&gt; Property. So lets take a look at our new &lt;b&gt;OnInit&lt;/b&gt; Method:


&lt;pre class="brush:csharp"&gt;override protected void OnInit(EventArgs e)
{
    //initialize our base class (System.Web,UI.Page)
    base.OnInit(e);
    //check to see if the Session is null (doesnt exist)
    if (Context.Session != null)
    {
        //check the IsNewSession value, this will tell us if the session has been reset.
        //IsNewSession will also let us know if the users session has timed out
        if (Session.IsNewSession)
        {
           //now we know it's a new session, so we check to see if a cookie is present
            string cookie = Request.Headers["Cookie"];
            //now we determine if there is a cookie does it contains what we're looking for
            if ((null != cookie) &amp;amp;&amp;amp; (cookie.IndexOf("ASP.NET_SessionId") &amp;gt;= 0))
            {
                //since it's a new session but a ASP.Net cookie exist we know
                //the session has expired so we need to redirect them
                Response.Redirect("Default.aspx?timeout=yes&amp;amp;success=no");
            }
        }
    }
}&lt;/pre&gt;&lt;/pre&gt;That's   it, we have completed our base class which all our web forms will   inherit from, allowing us to keep an eye on the users session. Now that   we have the class completed we need to use it. Before it can be   affected we need to do 1 of 2 things&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; Add EnableSessionState =  true to the &lt;b&gt;@Page&lt;/b&gt; directive on all pages that will  inherit from  our base class or&lt;/li&gt;
&lt;li&gt; Add the following line to the &lt;b&gt;&lt;system.web&gt;&lt;/system.web&gt;&lt;/b&gt;  section of  our web.config file:&lt;/li&gt;
&lt;/ul&gt;That's it, we have  completed our base class which all our web  forms will  inherit from,  allowing us to keep an eye on the users session. Now that  we have the  class completed we need to use it. Before it can be  affected we need to  do 1 of 2 things&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; Add EnableSessionState = true to the &lt;b&gt;@Page&lt;/b&gt;  directive on all pages that will inherit from  our base class or&lt;/li&gt;
&lt;li&gt;  Add the following line to the &lt;b&gt;&lt;system.web&gt;&lt;/system.web&gt;&lt;/b&gt;  section of  our web.config file&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre&gt;&lt;pages autoeventwireup="true" enablesessionstate="true" enableviewstate="true" enableviewstatemac="true" smartnavigation="true" validaterequest="false"&gt;
&lt;/pages&gt;&lt;/pre&gt;&lt;br /&gt;
Number 2 on that list will enable session state on all pages in the   web.  If you dont access session items in each of your pages, this might  be  overkill. Next we will need to inherit from our base class. Doing  this  will give our web form the following declaration&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;public partial class _Default : SessionCheck
{

}&lt;/pre&gt;&lt;br /&gt;
Then in the &lt;b&gt;Page_Load&lt;/b&gt; Event we will set the  redirect  URL for our base class&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;protected void Page_Load(object sender, EventArgs e)
{
    SessionCheck.URL = "Default.aspx";
}&lt;/pre&gt;&lt;br /&gt;
Now here is the entire base page in its entirety&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;//   A Base Page class for detecting session time outs
//
//   This program is free software: you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program.  If not, see &lt;http: licenses="" www.gnu.org=""&gt;.
//*****************************************************************************************

using System;
using System.Web.UI;

/// &lt;summary&gt;
/// This is a custom "base page" to inherit from which will be used
/// to check the session status. If the session has expired or is a timeout
/// we will redirect the user to the page we specify. In the page you use
/// to inherit this from you need to set EnableSessionState = True
/// &lt;/summary&gt;
public class SessionCheck : System.Web.UI.Page
{
    /// &lt;summary&gt;
    /// property vcariable for the URL Property
    /// &lt;/summary&gt;
    private static string _redirectUrl;

    /// &lt;summary&gt;
    /// property to hold the redirect url we will
    /// use if the users session is expired or has
    /// timed out.
    /// &lt;/summary&gt;
    public static string RedirectUrl
    {
        get { return _redirectUrl; }
        set { _redirectUrl = value; }
    }

        public SessionCheck()
        {
        _redirectUrl = string.Empty;
        }

    override protected void OnInit(EventArgs e)
    {
        //initialize our base class (System.Web,UI.Page)
        base.OnInit(e);
        //check to see if the Session is null (doesnt exist)
        if (Context.Session != null)
        {
            //check the IsNewSession value, this will tell us if the session has been reset.
            //IsNewSession will also let us know if the users session has timed out
            if (Session.IsNewSession)
            {
               //now we know it's a new session, so we check to see if a cookie is present
                string cookie = Request.Headers["Cookie"];
                //now we determine if there is a cookie does it contains what we're looking for
                if ((null != cookie) &amp;amp;&amp;amp; (cookie.IndexOf("ASP.NET_SessionId") &amp;gt;= 0))
                {
                    //since it's a new session but a ASP.Net cookie exist we know
                    //the session has expired so we need to redirect them
                    Response.Redirect("Default.aspx?timeout=yes&amp;amp;success=no");
                }
            }
        }
    }
}&lt;/pre&gt;&lt;br /&gt;
And there you have it, a custom base class that you can use to detect   session timeouts. I hope you found this tutorial helpful and useful, and   thank you for reading &lt;img alt=":)" src="http://http.cdnlayer.com/dreamincode/forums/public/style_emoticons/default/smile.gif" /&gt;&lt;br /&gt;
&lt;br /&gt;
Happy Coding!&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-4389892901161218302?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/I8h0_Wu9x-HwHPXiPRfZdUR2Hjw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/I8h0_Wu9x-HwHPXiPRfZdUR2Hjw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/I8h0_Wu9x-HwHPXiPRfZdUR2Hjw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/I8h0_Wu9x-HwHPXiPRfZdUR2Hjw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/6LxMwD1d4iU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/4389892901161218302/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/02/base-page-for-detecting-session-timeout.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/4389892901161218302?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/4389892901161218302?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/6LxMwD1d4iU/base-page-for-detecting-session-timeout.html" title="Base Page For Detecting Session Timeout in ASP.Net/C#" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/02/base-page-for-detecting-session-timeout.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUAFRng7fCp7ImA9WxBWGE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-3401189414554970511</id><published>2010-01-30T01:46:00.000-08:00</published><updated>2010-02-10T04:08:37.604-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T04:08:37.604-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.Net" /><title>Reading and Writing XML in C#</title><content type="html">In this article, you will see how to read and write XML documents in Microsoft .NET using C# language. First, I will discuss XML .NET Framework Library namespace and classes. Then, you will see how to read and write XML documents. In the end of this article, I will show you how to take advantage of ADO.NET and XML .NET model to read and write XML documents from relational databases and vice versa.&lt;br /&gt;
&lt;br /&gt;
Introduction to Microsoft .NET XML Namespaces and Classes Before start working with XML document&lt;br /&gt;
in .NET Framework, It is important to know about .NET namespace and classes provided by .NET Runtime Library. .NET provides five namespace - System.Xml, System.Xml.Schema, System.Xml.Serialization, System.Xml.XPath, and System.Xml.Xsl to support XML classes. The System.Xml namespace contains major XML classes. This namespace contains many classes to read and write XML documents. In this article, we are going to concentrate on reader and write class. These reader and writer classes are used to read and write XMl documents. These classes are - XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, and XmlTextWriter. As you can see there are four reader and two writer classes. The XmlReader class is an abstract bases classes and contains methods and properties to read a document. The Read method reads a node in the stream. Besides reading functionality, this class also contains methods to navigate through a document nodes. Some of these methods are MoveToAttribute,&amp;nbsp; MoveToFirstAttribute, MoveToContent, MoveToFirstContent, MoveToElement and&amp;nbsp; MoveToNextAttribute. ReadString, ReadInnerXml, ReadOuterXml, and ReadStartElement are more read methods. This class also has a method Skip to skip current node and move to next one. We'll see these methods in our sample example. The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. As their name explains, they are used to read text, node, and schemas. The XmlWrite class contains functionality to write data to XML documents. This class provides many write method to write XML document items. This class is base class for XmlTextWriter class, which we'll be using in our sample example. The XmlNode class plays an important role. Although, this class represents a single node of XML but that could be the root node of an XML document and could represent the entire file. This&amp;nbsp; class is an abstract base class for many useful classes for inserting, removing, and replacing nodes, navigating through the document. It also contains properties to get a parent or child, name, last child, node type and more. Three major classes derived from XmlNode are XmlDocument, XmlDataDocument and XmlDocumentFragment. XmlDocument class represents an XML document and provides methods and properties to load and save a document. It also provides functionality to add XML items such as attributes, comments, spaces, elements, and new nodes.&lt;br /&gt;
&lt;br /&gt;
The Load and LoadXml methods can be used to load XML documents and Save method to save a document respectively. XmlDocumentFragment class represents a document fragment, which can be used to add to a document. The XmlDataDocument class provides methods and properties to work with ADO.NET data set objects. In spite of above discussed classes, System.Xml namespace contains more classes. Few of them are XmlConvert, XmlLinkedNode, and XmlNodeList. Next namespace in Xml series is&amp;nbsp; System.Xml.Schema.&lt;br /&gt;
&lt;br /&gt;
It classes&amp;nbsp; to work with XML schemas such XmlSchema, XmlSchemaAll, XmlSchemaXPath, XmlSchemaType. The System.Xml.Serialization namespace contains classes that are used to serialize objects into XML format documents or streams. The System.Xml.XPath Namespce contains XPath related classes to use XPath specifications. This namespace has following classes&amp;nbsp; -XPathDocument, XPathExression, XPathNavigator, and XPathNodeIterator. With the help of XpathDocument, XpathNavigator provides a fast&lt;br /&gt;
navigation though XML documents. This class contains many Move methods to move through a document. The System.Xml.Xsl namespace contains classes to work with XSL/T transformations. Reading XML Documents In my sample application, I'm using books.xml to read and display its data through XmlTextReader. This file comes with VS.NET samples. You can search this on your machine and change the path of the file in the following line: XmlTextReader textReader = new XmlTextReader("C:\\books.xml"); Or you can use any XML file. The XmlTextReader, XmlNodeReader and XmlValidatingReader classes&lt;br /&gt;
are derived from XmlReader class. Besides XmlReader methods and properties, these classes also contain members to read text, node, and schemas respectively. I am using XmlTextReader class to read an XML file. You read a file by passing file name as a parameter in constructor. XmlTextReader textReader = new XmlTextReader("C:\\books.xml"); After creating an instance of XmlTextReader, you call Read method to start reading the document. After read method is called, you can read all information and data stored in a document. XmlReader class has properties such as Name, BaseURI, Depth, LineNumber an so on. List 1 reads a document and displays a node information using these properties. About Sample Example 1 In this sample example, I read an XML file using XmlTextReader and call Read method to read its node one by one until end of file and display the contents to the console output. Sample Example 1.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;using System;

using System.Xml;

namespace ReadXml1

{

    class Class1

    {

        static void Main(string[] args)

        {

            // Create an isntance of XmlTextReader and call Read method to read the file

            XmlTextReader textReader = new XmlTextReader("C:\\books.xml");

            textReader.Read();

            // If the node has value

            while (textReader.Read())

            {

                // Move to fist element

                textReader.MoveToElement();

                Console.WriteLine("XmlTextReader Properties Test");

                Console.WriteLine("===================");

                // Read this element's properties and display them on console

                Console.WriteLine("Name:" + textReader.Name);

                Console.WriteLine("Base URI:" + textReader.BaseURI);

                Console.WriteLine("Local Name:" + textReader.LocalName);

                Console.WriteLine("Attribute Count:" + textReader.AttributeCount.ToString());

                Console.WriteLine("Depth:" + textReader.Depth.ToString());

                Console.WriteLine("Line Number:" + textReader.LineNumber.ToString());

                Console.WriteLine("Node Type:" + textReader.NodeType.ToString());

                Console.WriteLine("Attribute Count:" + textReader.Value.ToString());

            }

        }

    }

}&lt;/pre&gt;&lt;br /&gt;
The NodeType property of XmlTextReader is important when you want to know the content type of a document. The XmlNodeType enumeration has a member for each type of XML item such as Attribute, CDATA, Element, Comment, Document, DocumentType, Entity, ProcessInstruction, WhiteSpace and so on. List 2 code sample reads an XML document, finds a node type and writes information at the end with how many node types a document has. About Sample Example 2 In this sample example, I read an XML file using XmlTextReader and call Read method to read its node one by one until end of the file. After reading a node, I check its NodeType property to find the node and write node contents to the console and keep track of number of particular type of nodes. In the end, I display total number of different types of nodes in the document. Sample Example 2.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;using System;

using System.Xml;

namespace ReadingXML2

{

    class Class1

    {

        static void Main(string[] args)

        {

            int ws = 0;

            int pi = 0;

            int dc = 0;

            int cc = 0;

            int ac = 0;

            int et = 0;

            int el = 0;

            int xd = 0;

            // Read a document

            XmlTextReader textReader = new XmlTextReader("C:\\books.xml");

            // Read until end of file

            while (textReader.Read())

            {

                XmlNodeType nType = textReader.NodeType;

                // If node type us a declaration

                if (nType == XmlNodeType.XmlDeclaration)

                {

                    Console.WriteLine("Declaration:" + textReader.Name.ToString());

                    xd = xd + 1;

                }

                // if node type is a comment

                if (nType == XmlNodeType.Comment)

                {

                    Console.WriteLine("Comment:" + textReader.Name.ToString());

                    cc = cc + 1;

                }

                // if node type us an attribute

                if (nType == XmlNodeType.Attribute)

                {

                    Console.WriteLine("Attribute:" + textReader.Name.ToString());

                    ac = ac + 1;

                }

                // if node type is an element

                if (nType == XmlNodeType.Element)

                {

                    Console.WriteLine("Element:" + textReader.Name.ToString());

                    el = el + 1;

                }

                // if node type is an entity\

                if (nType == XmlNodeType.Entity)

                {

                    Console.WriteLine("Entity:" + textReader.Name.ToString());

                    et = et + 1;

                }

                // if node type is a Process Instruction

                if (nType == XmlNodeType.Entity)

                {

                    Console.WriteLine("Entity:" + textReader.Name.ToString());

                    pi = pi + 1;

                }

                // if node type a document

                if (nType == XmlNodeType.DocumentType)

                {

                    Console.WriteLine("Document:" + textReader.Name.ToString());

                    dc = dc + 1;

                }

                // if node type is white space

                if (nType == XmlNodeType.Whitespace)

                {

                    Console.WriteLine("WhiteSpace:" + textReader.Name.ToString());

                    ws = ws + 1;

                }

            }

            // Write the summary

            Console.WriteLine("Total Comments:" + cc.ToString());

            Console.WriteLine("Total Attributes:" + ac.ToString());

            Console.WriteLine("Total Elements:" + el.ToString());

            Console.WriteLine("Total Entity:" + et.ToString());

            Console.WriteLine("Total Process Instructions:" + pi.ToString());

            Console.WriteLine("Total Declaration:" + xd.ToString());

            Console.WriteLine("Total DocumentType:" + dc.ToString());

            Console.WriteLine("Total WhiteSpaces:" + ws.ToString());

        }

    }

}&lt;/pre&gt;&lt;br /&gt;
Writing XML Documents XmlWriter class contains the functionality to write to XML documents. It is an abstract base class used through XmlTextWriter and XmlNodeWriter classes. It contains methods and properties to write to XML documents. This class has several Writexxx method to write every type of item of an XML document. For example, WriteNode, WriteString, WriteAttributes, WriteStartElement, and WriteEndElement are some of them. Some of these methods are used in a start and end pair. For example,&lt;br /&gt;
to write an element, you need to call WriteStartElement then write a string followed by WriteEndElement.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
Besides many methods, this class has three properties. WriteState, XmlLang, and XmlSpace. The WriteState gets and sets the state of the XmlWriter class. Although, it's not possible to describe all the Writexxx methods here, let's see some of them. First thing we need to do is create an instance of XmlTextWriter using its&amp;nbsp; constructor. XmlTextWriter has three overloaded constructors, which can take a string, stream, or a TextWriter as an argument. We'll pass a string (file name) as an argument, which we're going to create in C:\ root. In my sample example, I create a file myXmlFile.xml in C:\\ root directory. // Create a new file in C:\\ dir XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml", null) ; After creating an instance, first&lt;br /&gt;
thing you call us WriterStartDocument. When you're done writing, you call WriteEndDocument and TextWriter's Close method. textWriter.WriteStartDocument(); textWriter.WriteEndDocument(); textWriter.Close(); The WriteStartDocument and WriteEndDocument methods open and close a document for writing. You must have to open a document before start writing to it.&amp;nbsp; WriteComment method writes comment to a document. It takes only one string type of argument. WriteString method writes a string to a document. With the help of WriteString, WriteStartElement and WriteEndElement methods pair can be used&amp;nbsp; to write an element to a document. The WriteStartAttribute and WriteEndAttribute pair writes an attribute. WriteNode is more write method, which writes an XmlReader to a document as a node of the document. For example, you can use WriteProcessingInstruction and WriteDocType methods to write a ProcessingInstruction and DocType items of a document. //Write the ProcessingInstruction node string PI= "type='text/xsl' href='book.xsl'" textWriter.WriteProcessingInstruction("xml-stylesheet", PI); //'Write the DocumentType node textWriter.WriteDocType("book", Nothing, Nothing, ""); The below sample example summarizes all these methods and creates a new xml document with some items in it such as elements, attributes, strings, comments and so on. See Listing 5-14. In this sample example, we create a new xml file c:\xmlWriterText.xml. In this sample example, We create a new xml file c:\xmlWriterTest.xml using XmlTextWriter: After that, we add comments and elements to the document using Writexxx methods. After that we read our books.xml xml file using XmlTextReader and add its elements to xmlWriterTest.xml using XmlTextWriter. About Sample Example 3 In this sample example, I create a new file myxmlFile.xml using XmlTextWriter and use its various write methods to write XML items. Sample Example 3.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;using System;

using System.Xml;

namespace ReadingXML2

{

    class Class1

    {

        static void Main(string[] args)

        {

            // Create a new file in C:\\ dir

            XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml", null);

            // Opens the document

            textWriter.WriteStartDocument();

            // Write comments

            textWriter.WriteComment("First Comment XmlTextWriter Sample Example");

            textWriter.WriteComment("myXmlFile.xml in root dir");

            // Write first element

            textWriter.WriteStartElement("Student");

            textWriter.WriteStartElement("r", "RECORD", "urn:record");

            // Write next element

            textWriter.WriteStartElement("Name", "");

            textWriter.WriteString("Student");

            textWriter.WriteEndElement();

            // Write one more element

            textWriter.WriteStartElement("Address", ""); textWriter.WriteString("Colony");

            textWriter.WriteEndElement();

            // WriteChars

            char[] ch = new char[3];

            ch[0] = 'a';

            ch[1] = 'r';

            ch[2] = 'c';

            textWriter.WriteStartElement("Char");

            textWriter.WriteChars(ch, 0, ch.Length);

            textWriter.WriteEndElement();

            // Ends the document.

            textWriter.WriteEndDocument();

            // close writer

            textWriter.Close();

        }

    }

}
&lt;/pre&gt;&lt;br /&gt;
Using XmlDocument The XmlDocument class represents an XML document. This class provides similar methods and properties we've discussed earlier in this article. Load and LoadXml are two useful methods of this class. A Load method loads XML data from a string, stream, TextReader or XmlReader. LoadXml method loads XML document from a specified string. Another useful method of this class is Save. Using Save method you can write XML data to a string, stream, TextWriter or XmlWriter. About Sample Example 4 This tiny sample example pretty easy to understand. We call LoadXml method of XmlDocument to load an XML fragment and call Save to save the fragment as an XML file. Sample Example 4.&lt;br /&gt;
&lt;br /&gt;
//Create the XmlDocument. XmlDocument doc = new XmlDocument();&lt;br /&gt;
doc.LoadXml(("&lt;student section="B" type="regular"&gt;&lt;name&gt;Tommyex&lt;/name&gt;&lt;/student&gt;")); //Save the document to a file. doc.Save("C:\\std.xml");&lt;br /&gt;
&lt;br /&gt;
You can also use Save method to display contents on console if you pass Console.Out as a arameter. For example: doc.Save(Console.Out); About Sample Example 5 Here is one example of how to load an XML document using XmlTextReader. In this sample example, we read books.xml file using XmlTextReader and call its Read method. After that we call XmlDocumetn's Load method to load XmlTextReader contents to XmlDocument and call Save method to save the document. Passing Console.Out as a Save method&lt;br /&gt;
argument displays data on the console Sample Example 5. XmlDocument doc = new XmlDocument();&lt;br /&gt;
//Load the the document with the last book node.&lt;br /&gt;
XmlTextReader reader = new XmlTextReader("c:\\books.xml");&lt;br /&gt;
reader.Read(); // load reader doc.Load(reader); // Display contents on the console&lt;br /&gt;
doc.Save(Console.Out); Writing Data from a database to an XML Document Using XML and ADO.NET mode, reading a database and writing to an XML document and vice versa is not a big deal. In this section of this article, you will see how to read a database table's data and write the contents to an XML document. The DataSet class provides method to read a relational database table and write this table to an XML file.&lt;br /&gt;
You use WriteXml method to write a dataset data to an XML file. In this sample example, I have used commonly used Northwind database comes with Office 2000 and later versions. You can use any database you want. Only thing you need to do is just chapter the connection string and SELECT SQ L query. About Sample Example 6 &amp;nbsp;In this sample, I reate a data adapter object and selects all records of Customers table. After that I can fill method to fill a dataset from the data adapter. In this sample example,I have used OldDb data provides. You need to add reference to the Syste.Data.OldDb namespace to use OldDb data adapters in your program. As you can see from Sample Example 6, first I create a connection with northwind database using OldDbConnection. After that I create a data adapter object by passing a SELECT SQL query and connection. Once you have a data adapter, you can fill a dataset object using Fill method of the data adapter. Then you can WriteXml method of DataSet, which creates an XML document and write its contents to the XML document. In our sample, we read Customers table records and write DataSet contents to OutputXml.Xml file in C:\ dir. Sample Example 6.&lt;br /&gt;
using System;  using System.Xml;  using System.Data;  using System.Data.OleDb;  namespace ReadingXML2  {      class Class1      {          static void Main(string[] args)          {              // create a connection              OleDbConnection con = new OleDbConnection();              con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb";              // create a data adapter              OleDbDataAdapter da = new OleDbDataAdapter("Select * from Customers", con);              // create a new dataset              DataSet ds = new DataSet();              // fill dataset              da.Fill(ds, "Customers");              // write dataset contents to an xml file by calling WriteXml method              ds.WriteXml("C:\\OutputXML.xml");          }      }  } &lt;br /&gt;
&lt;br /&gt;
.NET Framework Library provides a good support to work with XML documents. The XmlReader,&lt;br /&gt;
XmlWriter and their derived classes contains methods and properties to read and write XML documents. With the help of the XmlDocument and XmlDataDocument classes, you can read entire document. The Load and Save method of XmlDocument loads a reader or a file and saves document respectively. ADO.NET provides functionality to read a database and write its contents to the XML document using data providers and a DataSet object.&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-3401189414554970511?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TGsZKXxBBsbwuANrnMQBWJP-pQc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TGsZKXxBBsbwuANrnMQBWJP-pQc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TGsZKXxBBsbwuANrnMQBWJP-pQc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TGsZKXxBBsbwuANrnMQBWJP-pQc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/4kUCSCPLHlk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/3401189414554970511/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/01/reading-and-writing-xml-in-c.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/3401189414554970511?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/3401189414554970511?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/4kUCSCPLHlk/reading-and-writing-xml-in-c.html" title="Reading and Writing XML in C#" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/01/reading-and-writing-xml-in-c.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8GQXY-eSp7ImA9WxBXGE8.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-7989421543871179486</id><published>2010-01-29T21:20:00.000-08:00</published><updated>2010-01-29T21:20:20.851-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-29T21:20:20.851-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.Net" /><title>Main Differences between ASP.NET 3.5 and ASP.NET 4.0</title><content type="html">&lt;span id="ctl00_ContentPlaceHolder1_lblDescription" style="color: darkblue;"&gt;As we all know, ASP.NET 3.5 has introduced with the following  main new features&lt;br /&gt;
&lt;br /&gt;
1) AJAX integration&lt;br /&gt;
2) LINQ&lt;br /&gt;
3) Automatic Properties&lt;br /&gt;
4) Lambda expressions&lt;br /&gt;
&lt;br /&gt;
I hope it  would be useful for everyone to know about the differences about asp.net  3.5 and its next version asp.net 4.0&lt;br /&gt;
&lt;br /&gt;
Because of space  consumption I’ll list only some of them here.&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;1) Client Data  access:&lt;/h1&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET 3.5:&lt;/b&gt; There is no direct method to  access data from client side. We can go for any of these methods&lt;br /&gt;
&lt;br /&gt;
1)  Pagemethods of script manager&lt;br /&gt;
2) ICallbackEventHandler interface&lt;br /&gt;
3)  XMLHttphanlder component&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET 4.0:&lt;/b&gt; In this framework  there is an inbuilt feature for this. Following are the methods to  implement them.&lt;br /&gt;
&lt;br /&gt;
1) Client data controls &lt;br /&gt;
2) Client templates &lt;br /&gt;
3)  Client data context &lt;br /&gt;
&lt;br /&gt;
i.e we can access the data through client  data view &amp;amp; data context objects from client side.&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;2)   Setting Meta keyword and Meta description:&lt;/h1&gt;&lt;br /&gt;
&lt;br /&gt;
Meta keywords and  description are really useful for getting listed in search engine.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET  3.5:&lt;/b&gt; It has a feature to add meta as following tag&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;pre&gt;&amp;amp;ltmeta name="keywords" content="These, are, my, keywords" /&amp;gt; 
  &amp;amp;ltmeta name="description" content="This is the description of my page" /&amp;gt; &lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET  4.0:&lt;/b&gt; Here we can add the keywords and description in Page  directives itself as shown below.&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;pre&gt;&amp;lt; %@ Page Language="C#"  CodeFile="Default.aspx.cs" 
  Inherits="_Default" 
  Keywords="Keyword1,Key2,Key3,etc" 
  Description="description" %&amp;gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;3)  Enableviewstage property for each control&lt;/h1&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET 3.5:&lt;/b&gt;  this property has two values “True” or “false”&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET 4.0:&lt;/b&gt;  ViewStateMode property takes an enumeration that has three values:  Enabled, Disabled, and Inherit.&lt;br /&gt;
Here inherit is the default value for  child controls of a control.&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;4) Setting Client IDs&lt;/h1&gt;&lt;br /&gt;
&lt;br /&gt;
Some  times ClientID property creates head ach for the programmers. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET  3.5:&lt;/b&gt; We have to use ClientID property to  find out the id which is  dynamically generated &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET 4.0:&lt;/b&gt; The new ClientIDMode  property is introduced to minimize the issues of earlier versions of  ASP.NET.&lt;br /&gt;
&lt;br /&gt;
It has following values.&lt;br /&gt;
&lt;br /&gt;
AutoID – Same as  ASP.NET 3.5&lt;br /&gt;
Static – There won’t be any separate clientid generated  at run time&lt;br /&gt;
Predictable-These are used particularly in datacontrols.  Format is like clientIDrowsuffix with the clientid vlaue&lt;br /&gt;
Inherit-  This value specifies that a control's ID generation is the same as its  parent.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span id="ctl00_ContentPlaceHolder1_lblDescription" style="color: darkblue;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span id="ctl00_ContentPlaceHolder1_lblDescription" style="color: darkblue;"&gt;--&lt;/span&gt;&lt;br /&gt;
&lt;span id="ctl00_ContentPlaceHolder1_lblDescription" style="color: darkblue;"&gt;happy programming.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-7989421543871179486?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2tTfRTs2GMcogNkQZMEzC_5R1lc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2tTfRTs2GMcogNkQZMEzC_5R1lc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2tTfRTs2GMcogNkQZMEzC_5R1lc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2tTfRTs2GMcogNkQZMEzC_5R1lc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/9JjDn8cYlzw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/7989421543871179486/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/01/main-differences-between-aspnet-35-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7989421543871179486?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7989421543871179486?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/9JjDn8cYlzw/main-differences-between-aspnet-35-and.html" title="Main Differences between ASP.NET 3.5 and ASP.NET 4.0" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/01/main-differences-between-aspnet-35-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck8FRn4_eip7ImA9WxBXFE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-2918306507845538079</id><published>2010-01-24T22:26:00.000-08:00</published><updated>2010-01-24T22:26:57.042-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-24T22:26:57.042-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.Net" /><title>.Net Memory Management &amp; Garbage Collection</title><content type="html">The Microsoft .NET common language runtime requires that all resources be allocated from the managed heap. Objects are automatically freed when they are no longer needed by the application. &lt;br /&gt;
When a process is initialized, the runtime reserves a contiguous region of address space that initially has no storage allocated for it. This address space region is the managed heap. The heap also maintains a pointer. This pointer indicates where the next object is to be allocated within the heap. Initially, the pointer is set to the base address of the reserved address space region. &lt;br /&gt;
Garbage collection in the Microsoft .NET common language runtime environment completely absolves the developer from tracking memory usage and knowing when to free memory. However, you’ll want to understand how it works. So let’s do it.&lt;br /&gt;
&lt;b&gt;Topics Covered&lt;/b&gt; &lt;br /&gt;
We will cover the following topics in the article &lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Why memory matters &lt;/li&gt;
&lt;li&gt;.Net Memory and garbage collection &lt;/li&gt;
&lt;li&gt;Generational garbage collection &lt;/li&gt;
&lt;li&gt;Temporary Objects &lt;/li&gt;
&lt;li&gt;Large object heap &amp;amp; Fragmentation &lt;/li&gt;
&lt;li&gt;Finalization &lt;/li&gt;
&lt;li&gt;Memory problems &lt;/li&gt;
&lt;/ol&gt;&lt;h3&gt;1) Why Memory Matters &lt;/h3&gt;Insufficient use of memory can impact &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Performance &lt;/li&gt;
&lt;li&gt;Stability &lt;/li&gt;
&lt;li&gt;Scalability &lt;/li&gt;
&lt;li&gt;Other applications &lt;/li&gt;
&lt;/ul&gt;Hidden problem in code can cause &lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Memory leaks &lt;/li&gt;
&lt;li&gt;Excessive memory usage &lt;/li&gt;
&lt;li&gt;Unnecessary performance overhead &lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;2) .Net Memory and garbage collection&lt;/h3&gt;.Net manages memory automatically &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Creates objects into memory blocks(heaps) &lt;/li&gt;
&lt;li&gt;Destroy objects no longer in use &lt;/li&gt;
&lt;/ul&gt;Allocates objects onto one of two heaps &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Small object heap(SOH) – objects &amp;lt; 85k &lt;/li&gt;
&lt;li&gt;Large object heap(LOH) – objects &amp;gt;= 85k &lt;/li&gt;
&lt;/ul&gt;You allocate onto the heap whenever you use the “new” keyword in code&lt;br /&gt;
&lt;b&gt;Small object heap&lt;/b&gt; (SOH)&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Allocation of objects &amp;lt; 85k – Contiguous heap – Objects allocated consecutively &lt;/li&gt;
&lt;li&gt;Next object pointer is maintained – Objects references held on Stack, Globals, Statics and CPU register &lt;/li&gt;
&lt;li&gt;Objects not in use are garbage collected &lt;/li&gt;
&lt;/ul&gt;Figure-1&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/soh_1.png" target="_blank"&gt;&lt;img alt="SOH_1" border="0" height="184" src="http://ramanisandeep.files.wordpress.com/2010/01/soh_1_thumb.png?w=244&amp;amp;h=184" style="border-width: 0pt; display: inline;" title="SOH_1" width="244" /&gt;&lt;/a&gt;&lt;br /&gt;
Next, How GC works in SOH?&lt;br /&gt;
GC Collect the objects based on the following rules:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Reclaims memory from “rootless” objects &lt;/li&gt;
&lt;li&gt;Runs whenever memory usage reaches certain thresholds &lt;/li&gt;
&lt;li&gt;Identifies all objects still “in use”&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Has root reference &lt;/li&gt;
&lt;li&gt;Has an ancestor with a root reference &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Compacts the heap&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Copies “rooted” objects over rootless ones &lt;/li&gt;
&lt;li&gt;Resets the next object pointer &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Freezes all execution threads during GC&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Every GC runs it&amp;nbsp;&amp;nbsp; hit the performance of your app &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;Figure-2 &lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/soh2.png" target="_blank"&gt;&lt;img alt="SOH2" border="0" height="183" src="http://ramanisandeep.files.wordpress.com/2010/01/soh2_thumb.png?w=244&amp;amp;h=183" style="border-width: 0pt; display: inline;" title="SOH2" width="244" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;3) Generational garbage collection&lt;/h3&gt;&lt;br /&gt;
Optimizing Garbage collection &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Newest object usually dies quickly &lt;/li&gt;
&lt;li&gt;Oldest object tend to stay alive &lt;/li&gt;
&lt;li&gt;GC groups objects into Generations&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Short lived – Gen 0 &lt;/li&gt;
&lt;li&gt;Medium – Gen 1 &lt;/li&gt;
&lt;li&gt;Long Lived – Gen 2 &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;When an object survives a GC it is promoted to the next generation &lt;/li&gt;
&lt;li&gt;GC compacts Gen 0 objects most often &lt;/li&gt;
&lt;li&gt;The more the GC runs the bigger the impact on performance &lt;/li&gt;
&lt;/ul&gt;Figure-3&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/generations_3.png" target="_blank"&gt;&lt;img alt="Generations_3" border="0" height="183" src="http://ramanisandeep.files.wordpress.com/2010/01/generations_3_thumb.png?w=244&amp;amp;h=183" style="border-width: 0pt; display: inline;" title="Generations_3" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
Figure-4&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/generations_4.png" target="_blank"&gt;&lt;img alt="Generations_4" border="0" height="183" src="http://ramanisandeep.files.wordpress.com/2010/01/generations_4_thumb.png?w=244&amp;amp;h=183" style="border-width: 0pt; display: inline;" title="Generations_4" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
Here object C is no longer referenced by any one so when GC runs it get destroyed &amp;amp; Object D will be moved to the Gen 1 (see figure-5). Now Gen 0 has no object, so when next time when GC runs it will collect object from Gen 1.&lt;br /&gt;
&lt;br /&gt;
Figure-5&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/generations_5.png" target="_blank"&gt;&lt;img alt="Generations_5" border="0" height="184" src="http://ramanisandeep.files.wordpress.com/2010/01/generations_5_thumb.png?w=244&amp;amp;h=184" style="border-width: 0pt; display: inline;" title="Generations_5" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
Figure-6&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/generations_6.png" target="_blank"&gt;&lt;img alt="Generations_6" border="0" height="183" src="http://ramanisandeep.files.wordpress.com/2010/01/generations_6_thumb.png?w=244&amp;amp;h=183" style="border-width: 0pt; display: inline;" title="Generations_6" width="244" /&gt;&lt;/a&gt;&lt;br /&gt;
Here when GC runs it will move the object D &amp;amp; B to Gen 2 because it has been referenced by Global objects &amp;amp; Static objects.&lt;br /&gt;
Figure-7&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/generations_7.png" target="_blank"&gt;&lt;img alt="Generations_7" border="0" height="182" src="http://ramanisandeep.files.wordpress.com/2010/01/generations_7_thumb.png?w=244&amp;amp;h=182" style="border-width: 0pt; display: inline;" title="Generations_7" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
Here when GC runs for Gen 2 it will find out that object A is no longer referenced by anyone so it will destroy it &amp;amp; frees his memory. Now Gen 2 has only object D &amp;amp; B.&lt;br /&gt;
&lt;b&gt;Garbage collector runs when&lt;/b&gt; &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Gen 0 objects reach ~256k &lt;/li&gt;
&lt;li&gt;Gen 1 objects reach ~2Meg &lt;/li&gt;
&lt;li&gt;Gen 2 objects reach ~10Meg &lt;/li&gt;
&lt;li&gt;System memory is low &lt;/li&gt;
&lt;/ul&gt;Most objects should die in Gen 0. &lt;br /&gt;
Impact on performance is very high when Gen 2 run because&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Entire small object heap is compacted &lt;/li&gt;
&lt;li&gt;Large object heap is collected &lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;4) Temporary objects&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Once allocated objects can’t resize on a contiguous heap &lt;/li&gt;
&lt;li&gt;Objects such as strings are Immutable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Can’t be changed, new versions created instead &lt;/li&gt;
&lt;li&gt;Heap fills with temporary objects &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;Let us take example to understand this scenario.&lt;br /&gt;
Figure – 8 &lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/tempobj_8.png" target="_blank"&gt;&lt;img alt="TempObj_8" border="0" height="97" src="http://ramanisandeep.files.wordpress.com/2010/01/tempobj_8_thumb.png?w=244&amp;amp;h=97" style="border-width: 0pt; display: inline;" title="TempObj_8" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
After the GC runs all the temporary objects are destroyed. &lt;br /&gt;
Figure–9 &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/tempobj_9.png" target="_blank"&gt;&lt;img alt="TempObj_9" border="0" height="94" src="http://ramanisandeep.files.wordpress.com/2010/01/tempobj_9_thumb.png?w=244&amp;amp;h=94" style="border-width: 0pt; display: inline;" title="TempObj_9" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;h3&gt;5) Large object heap &amp;amp; Fragmentation&lt;/h3&gt;Large object heap (LOH) &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Allocation of object &amp;gt;=85k &lt;/li&gt;
&lt;li&gt;Non contiguous heap&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Objects allocated using free space table &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Garbage collected when LOH Threshold Is reached &lt;/li&gt;
&lt;li&gt;Uses free space table to find where to allocate &lt;/li&gt;
&lt;li&gt;Memory can become fragmented &lt;/li&gt;
&lt;/ul&gt;Figure-10&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/loh_10.png" target="_blank"&gt;&lt;img alt="LOH_10" border="0" height="181" src="http://ramanisandeep.files.wordpress.com/2010/01/loh_10_thumb.png?w=244&amp;amp;h=181" style="border-width: 0pt; display: inline;" title="LOH_10" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
After object B is destroyed free space table will be filled with a memory address which has been available now.&lt;br /&gt;
Figure-11&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/loh_11.png" target="_blank"&gt;&lt;img alt="LOH_11" border="0" height="182" src="http://ramanisandeep.files.wordpress.com/2010/01/loh_11_thumb.png?w=244&amp;amp;h=182" style="border-width: 0pt; display: inline;" title="LOH_11" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
Now when you create new object, GC will check out which memory area is free or available for our new object in LOH. It will check out the Free space table &amp;amp; allocate object where it fit.&lt;br /&gt;
Figure-12&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/loh_12.png" target="_blank"&gt;&lt;img alt="LOH_12" border="0" height="183" src="http://ramanisandeep.files.wordpress.com/2010/01/loh_12_thumb.png?w=244&amp;amp;h=183" style="border-width: 0pt; display: inline;" title="LOH_12" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;h3&gt;6) Object Finalization&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Disk, Network, UI resources need safe cleanup after use by .NET classes &lt;/li&gt;
&lt;li&gt;Object finalization guarantees cleanup code will be called before collection &lt;/li&gt;
&lt;li&gt;Finalizable object survive for at least 1 extra GC &amp;amp; often make it to Gen 2 &lt;/li&gt;
&lt;li&gt;Finalizable classes have a&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Finalize method(c# or vb.net) &lt;/li&gt;
&lt;li&gt;C++ style destructor (c#) &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;Here are the guidelines that help you to decide when to use Finalize method:&lt;/b&gt; &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Only implement Finalize on objects that require finalization. There are performance costs associated with Finalize methods. &lt;/li&gt;
&lt;li&gt;If you require a Finalize method, you should consider implementing IDisposable to allow users of your class to avoid the cost of invoking the Finalize method. &lt;/li&gt;
&lt;li&gt;Do not make the Finalize method more visible. It should be protected, not public. &lt;/li&gt;
&lt;li&gt;An object’s Finalize method should free any external resources that the object owns. Moreover, a Finalize method should release only resources that are held onto by the object. The Finalize method should not reference any other objects. &lt;/li&gt;
&lt;li&gt;Do not directly call a Finalize method on an object other than the object’s base class. This is not a valid operation in the C# programming language. &lt;/li&gt;
&lt;li&gt;Call the base.Finalize method from an object’s Finalize method. &lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;Note:&lt;/b&gt; The base class’s Finalize method is called automatically with the C# and the Managed Extensions for C++ destructor syntax. &lt;br /&gt;
&lt;b&gt;Let see one example to understand how the finalization works.&lt;/b&gt; &lt;br /&gt;
Each figure itself explain what is going on &amp;amp; you can clearly see how the finalization works when GC run.&lt;br /&gt;
&lt;br /&gt;
Figure-13&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/final_13.png" target="_blank"&gt;&lt;img alt="Final_13" border="0" height="182" src="http://ramanisandeep.files.wordpress.com/2010/01/final_13_thumb.png?w=244&amp;amp;h=182" style="border-width: 0pt; display: inline;" title="Final_13" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
Figure-14&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/final_14.png" target="_blank"&gt;&lt;img alt="Final_14" border="0" height="182" src="http://ramanisandeep.files.wordpress.com/2010/01/final_14_thumb.png?w=244&amp;amp;h=182" style="border-width: 0pt; display: inline;" title="Final_14" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
Figure-15&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/final_15.png" target="_blank"&gt;&lt;img alt="Final_15" border="0" height="183" src="http://ramanisandeep.files.wordpress.com/2010/01/final_15_thumb.png?w=244&amp;amp;h=183" style="border-width: 0pt; display: inline;" title="Final_15" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
Figure-16&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/final_16.png" target="_blank"&gt;&lt;img alt="Final_16" border="0" height="182" src="http://ramanisandeep.files.wordpress.com/2010/01/final_16_thumb.png?w=244&amp;amp;h=182" style="border-width: 0pt; display: inline;" title="Final_16" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;
Figure-17&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://ramanisandeep.files.wordpress.com/2010/01/final_17.png" target="_blank"&gt;&lt;img alt="Final_17" border="0" height="183" src="http://ramanisandeep.files.wordpress.com/2010/01/final_17_thumb.png?w=244&amp;amp;h=183" style="border-width: 0pt; display: inline;" title="Final_17" width="244" /&gt;&lt;/a&gt;&lt;br /&gt;
For more information on Finalization refer the following links: &lt;br /&gt;
&lt;a href="http://www.object-arts.com/docs/index.html?howdofinalizationandmourningactuallywork_.htm" target="_blank"&gt;http://www.object-arts.com/docs/index.html?howdofinalizationandmourningactuallywork_.htm&lt;/a&gt;     &lt;br /&gt;
&lt;a href="http://blogs.msdn.com/cbrumme/archive/2004/02/20/77460.aspx" target="_blank"&gt;http://blogs.msdn.com/cbrumme/archive/2004/02/20/77460.aspx&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;How to minimize overheads &lt;/b&gt;&lt;br /&gt;
Object size, number of objects, and object lifetime are all factors that impact your application’s allocation profile. While allocations are quick, the efficiency of garbage collection depends (among other things) on the generation being collected. Collecting small objects from Gen 0 is the most efficient form of garbage collection because Gen 0 is the smallest and typically fits in the CPU cache. In contrast, frequent collection of objects from Gen 2 is expensive. To identify when allocations occur, and which generations they occur in, observe your application’s allocation patterns by using an allocation profiler such as the CLR Profiler. &lt;br /&gt;
You can minimize overheads by: &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Avoid Calling GC.Collect &lt;/li&gt;
&lt;li&gt;Consider Using Weak References with Cached Data &lt;/li&gt;
&lt;li&gt;Prevent the Promotion of Short-Lived Objects &lt;/li&gt;
&lt;li&gt;Set Unneeded Member Variables to Null Before Making Long-Running Calls &lt;/li&gt;
&lt;li&gt;Minimize Hidden Allocations &lt;/li&gt;
&lt;li&gt;Avoid or Minimize Complex Object Graphs &lt;/li&gt;
&lt;li&gt;Avoid Preallocating and Chunking Memory &lt;/li&gt;
&lt;/ul&gt;Read more: &lt;a href="http://www.guidanceshare.com/wiki/.NET_2.0_Performance_Guidelines_-_Garbage_Collection" target="_blank"&gt;http://www.guidanceshare.com/wiki/.NET_2.0_Performance_Guidelines_-_Garbage_Collection&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;7) Common Memory Problems&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Excessive RAM footprint&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;App allocates objects too early or for too long using more memory than needed &lt;/li&gt;
&lt;li&gt;Can affect other app on system &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Excessive temporary object allocation&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Garbage collection runs more frequently &lt;/li&gt;
&lt;li&gt;Executing threads freeze during garbage collection &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Memory leaks&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Overlooked root references keep objects alive (collections, arrays, session state, delegates/events etc) &lt;/li&gt;
&lt;li&gt;Incorrect or absent finalization can cause resource leaks &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;References &amp;amp; other useful articles related to this topic:&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/tkagarwal/MemoryManagementInNet11232005064832AM/MemoryManagementInNet.aspx" target="_blank"&gt;Link 1&lt;/a&gt;&lt;/b&gt; &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/bb985010.aspx" target="_blank"&gt;Link 2&lt;/a&gt;&lt;/b&gt; &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://www.red-gate.com/products/ants_memory_profiler/DOTNET_Memory_Management/Index.html" target="_blank"&gt;Link 3&lt;/a&gt;&lt;/b&gt; &lt;/li&gt;
&lt;/ul&gt;Hope this help&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-2918306507845538079?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_KLHkAHH4gnUAj6X7oDC4qVbXnE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_KLHkAHH4gnUAj6X7oDC4qVbXnE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_KLHkAHH4gnUAj6X7oDC4qVbXnE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_KLHkAHH4gnUAj6X7oDC4qVbXnE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/bP-xzpwJ-tU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/2918306507845538079/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/01/net-memory-management-garbage.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/2918306507845538079?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/2918306507845538079?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/bP-xzpwJ-tU/net-memory-management-garbage.html" title=".Net Memory Management &amp; Garbage Collection" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/01/net-memory-management-garbage.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMAQH46eSp7ImA9WxBRGEs.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-1335393290121559741</id><published>2010-01-07T04:47:00.000-08:00</published><updated>2010-01-07T04:47:21.011-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-07T04:47:21.011-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MYSQL" /><title>Backing Up MySQL Database</title><content type="html">&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"&gt;&lt;/meta&gt;&lt;meta content="Word.Document" name="ProgId"&gt;&lt;/meta&gt;&lt;meta content="Microsoft Word 11" name="Generator"&gt;&lt;/meta&gt;&lt;meta content="Microsoft Word 11" name="Originator"&gt;&lt;/meta&gt;&lt;link href="file:///C:%5CDOCUME%7E1%5Cyogesh%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List"&gt;&lt;/link&gt;&lt;o:smarttagtype name="Sn" namespaceuri="urn:schemas:contacts"&gt;&lt;/o:smarttagtype&gt;&lt;o:smarttagtype name="GivenName" namespaceuri="urn:schemas:contacts"&gt;&lt;/o:smarttagtype&gt;&lt;style&gt;
&lt;!--
 /* Font Definitions */
 @font-face
	{font-family:Century;
	panose-1:2 4 6 4 5 5 5 2 3 4;
	mso-font-charset:0;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:647 0 0 0 159 0;}
@font-face
	{font-family:Verdana;
	panose-1:2 11 6 4 3 5 4 4 2 4;
	mso-font-charset:0;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:536871559 0 0 0 415 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:Century;
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:Century;}
p
	{mso-margin-top-alt:auto;
	margin-right:0in;
	mso-margin-bottom-alt:auto;
	margin-left:0in;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:"Times New Roman";}
p.code, li.code, div.code
	{mso-style-name:code;
	mso-margin-top-alt:auto;
	margin-right:0in;
	mso-margin-bottom-alt:auto;
	margin-left:0in;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:"Times New Roman";}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
--&gt;
&lt;/style&gt;  &lt;br /&gt;
&lt;div style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;Backing Up MySQL Database&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;MySQL database backup can be accomplished in two ways:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;a) Copying the raw mysql database files &amp;amp;&lt;br /&gt;
b) Exporting tables to text files&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;b&gt;&lt;span style="font-family: Verdana;"&gt;Copying the MySQL database files&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family: Verdana;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;MySQL uses the same table format on different platforms, so it's possible to copy MySQL table and index files from one platform and use them on another without any difficulties (assuming, of course, that you're using the same version of MySQL on both platforms).&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;b&gt;&lt;span style="font-family: Verdana;"&gt;Exporting tables to text files&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family: Verdana;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;The MySQLDump is handy utility that can be used to quickly backup the MySQL Database to the text files. To use the MySQLDump utility it is required to logon to the System running the &lt;st1:givenname w:st="on"&gt;MySQL&lt;/st1:givenname&gt; &lt;st1:sn w:st="on"&gt;Databse&lt;/st1:sn&gt;. You can use Telnet to remotely logon to the system if you don't have the physical access to the machine.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;The syntax for the command is as follows.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;mysqldump -u &lt;i&gt;&lt;span style="font-family: Verdana;"&gt;[Username]&lt;/span&gt;&lt;/i&gt; -p&lt;i&gt;&lt;span style="font-family: Verdana;"&gt; [password]&lt;/span&gt;&lt;/i&gt; &lt;i&gt;&lt;span style="font-family: Verdana;"&gt;[databasename] &lt;/span&gt;&lt;/i&gt;&amp;gt; [&lt;i&gt;&lt;span style="font-family: Verdana;"&gt;backupfile.sql]&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
[username] - this is your database username&lt;br /&gt;
[password]- this is the password for your database&lt;br /&gt;
[databasename] - the name of your database&lt;br /&gt;
[backupfile.sql] - the filename for your database backup&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;Let's discuss the example of backing up MySQL Database named "accounts" into text file accounts.sql. Here are the scenarios of taking the backup assuming that both user name and password of the database is "admin".&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;a) Taking the full backup of all the tables including the data. &lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;Use the following command to accomplish this:&lt;br /&gt;
&lt;b&gt;&lt;i&gt;mysqldump -u admin -p admin accounts &amp;gt; accounts.sql&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;b) Taking the backup of table structures only. &lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;Use the following command to accomplish this:&lt;br /&gt;
&lt;b&gt;&lt;i&gt;mysqldump -u admin -p admin --no-data accounts &amp;gt; accounts.sql&lt;/i&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;c) Taking the backup data only. &lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;Use the following command to accomplish this:&lt;br /&gt;
&lt;b&gt;&lt;i&gt;mysqldump -u admin -p admin --no-create-info accounts &amp;gt; accounts.sql&lt;/i&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;b&gt;Restoring MySQL Database&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;Restoring the MySQL is very easy job. You can use the following to command to restore the accounts database from accounts.sql backup file.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;b&gt;&lt;span style="font-family: Verdana;"&gt;mysql - u admin -p admin accounts &amp;lt; accounts.sql&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family: Verdana;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;In this tutorial you learned how to take the backup of your MySQL Database and restore the same in the event of some database crash or on some other machine.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;o:p&gt;-----------&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="code" style="line-height: 150%;"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;o:p&gt;Enjoy Programming &lt;br /&gt;
&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: 150%;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-1335393290121559741?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/NG8sXQNIm8I_YMw7vNzZ4yFzKoQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NG8sXQNIm8I_YMw7vNzZ4yFzKoQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/NG8sXQNIm8I_YMw7vNzZ4yFzKoQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NG8sXQNIm8I_YMw7vNzZ4yFzKoQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/MqMto1QrYdI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/1335393290121559741/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/01/backing-up-mysql-database.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/1335393290121559741?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/1335393290121559741?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/MqMto1QrYdI/backing-up-mysql-database.html" title="Backing Up MySQL Database" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/01/backing-up-mysql-database.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcGRXw7eip7ImA9WxBWGE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-7164858831296433424</id><published>2010-01-03T22:26:00.000-08:00</published><updated>2010-02-10T04:13:44.202-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T04:13:44.202-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.Net" /><title>Uploading Multiple Files in ASP.NET 2.0</title><content type="html">In ASP.NET We can upload more than one file using the following classes:&lt;br /&gt;
&lt;br /&gt;
HttpFileCollection&lt;br /&gt;
HttpPostedFile&lt;br /&gt;
Request.Files&lt;br /&gt;
System.IO.Path&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;HttpFileCollection:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
HttpFileCollection will provide access to the files uploaded by a client.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;HttpPostedFile:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
HttpPostedFile will provide access to individual files uploaded by a client. Through this class we can access the content and properties of each individual file, and read and save the files.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Request.Files :&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Request.Files will return collection of all files uploaded by user and store them inside the HttpFileCollection.&lt;br /&gt;
&lt;br /&gt;
Follow these steps mentioned below to do so:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Drag and drop multiple (in our case four) FileUpload controls on to the designer.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 2:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Drop a Button control and rename it to “Upload”&lt;br /&gt;
&lt;pre class="brush:html"&gt;&amp;lt;asp:Button ID=”btnUpload” runat=”server” Text=”Upload” /&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Step 3:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Double click the Upload Button to add an event hander to the code behind.&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;protected void btnUpload_Click(object sender, EventArgs e)
{

}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Step 4: Import the System.IO namespace.&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;using System.IO;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Step 5:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Use the ‘HttpFileCollection’ class to retrieve all the files that are uploaded. Files are encoded and transmitted in the content body using multipart MIME format with an HTTP Content-Type header. ASP.NET extracts&lt;br /&gt;
this information from the content body into individual members of an HttpFileCollection.&lt;br /&gt;
&lt;br /&gt;
The code would look as follows:&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
for (int i = 0; i &amp;lt; hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength &amp;gt; 0)
{
hpf.SaveAs(Server.MapPath(”MyFiles”) + “\\” +
Path.GetFileName(hpf.FileName));

}
}
}
catch (Exception ex)
{
// Handle your exception here
}

}
&lt;/pre&gt;&lt;b&gt;Some important points to consider while uploading&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
1.&amp;nbsp;&amp;nbsp;&amp;nbsp; To save a file to the server, the account associated with ASP.NET must have sufficient permissions on the folder, where the files are being uploaded. This would usually be the ‘ASPNET’ account for Windows XP or a similar OS. In Windows Server 2003, the account used is ‘NETWORKSERVICE’. So you would be required to explicitly grant write permissions to these accounts on the folder.&lt;br /&gt;
&lt;br /&gt;
2.&amp;nbsp;&amp;nbsp;&amp;nbsp; While uploading the files to a remote server, the default ASPNET user account used by ASP.NET does not have network permissions by default. The solution is to either give the account such permissions or&lt;br /&gt;
use impersonation to have it run under a different account that has the permissions.&lt;br /&gt;
&lt;br /&gt;
3.&amp;nbsp;&amp;nbsp;&amp;nbsp; By default, you can upload no more than 4096 KB (4 MB) of data. However there is a workaround for this limitation. You can change the maximum file size by changing the maxRequestLength attribute of the&lt;br /&gt;
httpRuntime element in the web.config file. You can also increase the ‘executionTimeout’. By default it is 110 seconds. I would encourage you to experiment with the other attributes of the httpRuntime element.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:xhtml"&gt;&amp;lt;configuration&amp;gt;
&amp;lt;system.web&amp;gt;
&amp;lt;httpRuntime
executionTimeout=”200″
maxRequestLength=”8192″
requestLengthDiskThreshold=”256″
useFullyQualifiedRedirectUrl=”false”
minFreeThreads=”8″
minLocalRequestFreeThreads=”4″
appRequestQueueLimit=”5000″
enableKernelOutputCache=”true”
enableVersionHeader=”true”
requireRootedSaveAsPath=”true”
enable=”true”
shutdownTimeout=”90″
delayNotificationTimeout=”5″
waitChangeNotification=”0″
maxWaitChangeNotification=”0″
enableHeaderChecking=”true”
sendCacheControlHeader=”true”
apartmentThreading=”false”/&amp;gt;
&amp;lt;/system.web&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
References&lt;br /&gt;
&lt;br /&gt;
There are a number of good resources I referred to, for this article. A few of them are:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.wrox.com/WileyCDA/Section/id-292160.html"&gt;&lt;b&gt;http://www.wrox.com/WileyCDA/Section/id-292160.html&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://msdn2.microsoft.com/en-US/library/aa479405.aspx"&gt;&lt;b&gt;http://msdn2.microsoft.com/en-US/library/aa479405.aspx&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httpfilecollection.aspx"&gt;&lt;b&gt;http://msdn2.microsoft.com/en-us/library/system.web.httpfilecollection.aspx&lt;/b&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-7164858831296433424?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/d27k_XKSHkkCi5_2AErFy5_kizw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d27k_XKSHkkCi5_2AErFy5_kizw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/d27k_XKSHkkCi5_2AErFy5_kizw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d27k_XKSHkkCi5_2AErFy5_kizw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/JvzQIk_T4YM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/7164858831296433424/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2010/01/uploading-multiple-files-in-aspnet-20.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7164858831296433424?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/7164858831296433424?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/JvzQIk_T4YM/uploading-multiple-files-in-aspnet-20.html" title="Uploading Multiple Files in ASP.NET 2.0" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2010/01/uploading-multiple-files-in-aspnet-20.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUGQno6fyp7ImA9WxBREUs.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-5357470794479399993</id><published>2009-12-30T00:37:00.000-08:00</published><updated>2009-12-30T00:37:03.417-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-30T00:37:03.417-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>Some Sql Server Interview Questions</title><content type="html">&lt;b&gt;* Difference between Set and Select&lt;/b&gt;&lt;br /&gt;
Ans:&lt;br /&gt;
1) Set is a ANSI standard for variable assignment.&lt;br /&gt;
&amp;nbsp;&amp;nbsp; Select is a Non-ANSI standard when assigning variables.We can assign only one variable at a time&lt;br /&gt;
&lt;br /&gt;
2) We can assign multiple variable at a time.When assigning from a query that returns more than one value, SET will fail with an error.&lt;br /&gt;
&amp;nbsp;&amp;nbsp; When assigning from a query that returns more than one value, SELECT will assign the last value returned by the query and hide the fact that the query returned&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;* What is Network Packet Size in SQL&lt;/b&gt;&lt;br /&gt;
Ans:&lt;br /&gt;
NPS(Network Packet Size) is the size of the TDS (tabular data stream) packets used to communicate between your applications and your relational database engine and default packet size is 4 kilobytes and its manily depends on network packet size configuration option.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;* How many different locks in SQL SERVER&lt;/b&gt;&lt;br /&gt;
Ans:&lt;br /&gt;
(1)Intent&lt;br /&gt;
(2)shared&lt;br /&gt;
(3)Update&lt;br /&gt;
(4)Exclusive&lt;br /&gt;
(5)Schema&lt;br /&gt;
(6)Bulk Update&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;* Diffrence between temp table and table variable&lt;/b&gt;&lt;br /&gt;
Ans:&lt;br /&gt;
(1)Temp Tables are created in the SQL Server TEMPDB database and therefore require more IO resources and locking. Table Variables and Derived Tables are created in memory.&lt;br /&gt;
&lt;br /&gt;
(2)Temp Tables will generally perform better for large amounts of data that can be worked on using parallelism whereas Table Variables are best used for small amounts of data (I use a rule of thumb of 100 or less rows) where parallelism would not provide a significant performance improvement.&lt;br /&gt;
&lt;br /&gt;
(3)You cannot use a stored procedure to insert data into a Table Variable or Derived Table. For example, the following will work: INSERT INTO #MyTempTable EXEC dbo.GetPolicies_sp whereas the following will generate an error: INSERT INTO @MyTableVariable EXEC dbo.GetPolicies_sp.&lt;br /&gt;
&lt;br /&gt;
(4)Derived Tables can only be created from a SELECT statement but can be used within an Insert, Update, or Delete statement.&lt;br /&gt;
&lt;br /&gt;
(5) In order of scope endurance, Temp Tables extend the furthest in scope, followed by Table Variables, and finally Derived Tables.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;* What is Cursor&lt;/b&gt;&lt;br /&gt;
Ans:&lt;br /&gt;
&amp;nbsp; Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, instead of the typical SQL commands that operate on all the rows in the set at one time. For example, you can use cursor to include a list of all user databases and make multiple operations against each database by passing each database name as a variable&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;* Write some disadvantage of Cursor&lt;/b&gt;&lt;br /&gt;
Ans:&lt;br /&gt;
&amp;nbsp; Cursor plays there row quite nicely but although there are some disadvantage of Cursor . Because we know cursor doing roundtrip it will make network line busy and also make time consuming methods. First of all select query gernate output and after that cursor goes one by one so roundtrip happen.Another disadvange of cursor are ther are too costly because they require lot of resources and temporary storage so network is quite busy.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;* Can you tell me the difference between DELETE and TRUNCATE commands&lt;/b&gt;&lt;br /&gt;
Ans:&lt;br /&gt;
&amp;nbsp; Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command.&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-5357470794479399993?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uPvaAL0cSZdSH2bNWkSs2FmT9VQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uPvaAL0cSZdSH2bNWkSs2FmT9VQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uPvaAL0cSZdSH2bNWkSs2FmT9VQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uPvaAL0cSZdSH2bNWkSs2FmT9VQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/jyBb963MICM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/5357470794479399993/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2009/12/some-sql-server-interview-questions.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/5357470794479399993?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/5357470794479399993?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/jyBb963MICM/some-sql-server-interview-questions.html" title="Some Sql Server Interview Questions" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2009/12/some-sql-server-interview-questions.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8GRng6fSp7ImA9WxBWGE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-2363755376885264898</id><published>2009-12-24T02:40:00.000-08:00</published><updated>2010-02-10T04:27:07.615-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T04:27:07.615-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>How to pad a numeric type column with leading zeros?</title><content type="html">&lt;span style="color: blue; font-family: verdana;"&gt;Execute the following Microsoft SQL Server T-SQL example scripts to demonstrate SQL padding of numbers and strings with leading and trailing zeros as well as with other designated characters, and techniques&lt;br /&gt;
for removing (trim) leading zeros.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- SQL Server leading zero - T-SQL padding numbers - lpad tsql - sql pad zero

SELECT ListPrice,

  Padded=RIGHT('0000000000' + CONVERT(VARCHAR,ListPrice), 10)

FROM AdventureWorks2008.Production.Product WHERE ListPrice &amp;gt; 0.0

------------

-- T SQL pad leading zeros - transact sql leading zeros

SELECT ProductID, ReorderPoint = REPLACE(STR(ReorderPoint, 6), SPACE(1), '0')

FROM AdventureWorks2008.Production.Product

/* ProductID            ReorderPoint

      1                 000750

      2                 000750

      3                 000600  */

 ------------

-- SQL Server leading zero - SQL leading zeros - sql server pad leading zero

USE AdventureWorks2008;

DECLARE @Number int = 789

SELECT RIGHT ('000000'+ CAST (@Number AS varchar), 6)

-- 000789

------------

USE AdventureWorks;

-- SQL padding salary pay rate money data type with leading zeroes

-- SQL left pad number - prefix number with zeros - sql server leading zero

-- SQL convert number to text - cast number to varchar string

SELECT EmployeeID,

       Rate,

       PaddedRate = RIGHT(REPLICATE('0',8) + CAST(Rate AS VARCHAR(8)),8)

FROM   HumanResources.EmployeePayHistory
/* Partial results

EmployeeID        Rate              PaddedRate

1                 12.45             00012.45

2                 13.4615           00013.46

3                 43.2692           00043.27

*/


-- SQL zero padding ListPrice money data type - t sql leading zero

-- SQL left pad - T-SQL string concatenation - sql concat

-- SQL convert number to string - pad numeric with zeros

SELECT ProductID,

       ListPrice,

       PaddedListPrice = RIGHT(REPLICATE('0', 8) + CAST(ListPrice AS VARCHAR(8)),8)

FROM Production.Product

/* Results sample

ProductID               ListPrice               PaddedListPrice

965                     742.35                  00742.35

*/


-- SQL month leading zero - sql pad month number with zero

SELECT RIGHT('0' + convert(varchar(2), month(GetDate())), 2)

-- 06
----------

-- trim leading zeros - sql trim leading zeros - remove leading zeros sql

USE AdventureWorks2008;

DECLARE @num  varchar(32)= '00091234560'

SELECT      right(@num, len(@num)+1 - patindex('%[^0]%', @num))

-- 91234560

------------

-- SQL pad numeric data type - SQL pad digits - transact sql leading zeros

-- SQL pad with leading zeroes - append leading zeros - T-SQL top function

-- SQL pad with trailing zeroes - MSSQL append trailing zeros

-- SQL cast money to numeric - cast numeric to string - mssql newid function

SELECT TOP (5)

      ProductName = Name,

      ListPrice = RIGHT(REPLICATE('0', 10)

      + CAST(CAST(ListPrice AS NUMERIC(9,3)) AS VARCHAR) ,10)  

FROM AdventureWorks.Production.Product

ORDER BY NEWID()

/* ProductName                      ListPrice

LL Mountain Frame - Black, 40       000249.790

HL Touring Frame - Yellow, 46       001003.910

Bike Wash - Dissolver               000007.950

Metal Sheet 7                       000000.000

HL Road Frame - Red, 56             001431.500

*/

----------


-- PAD leading zeros function - sql server leading zeros - UDF

USE AdventureWorks2008;

GO

CREATE FUNCTION fnPadNumber

               (@n      DECIMAL(26,2),

                @length TINYINT)

RETURNS VARCHAR(32)

AS

  BEGIN

    RETURN ( replicate('0',@length - len(convert(VARCHAR(32),@n))) +

             convert(VARCHAR(32),@n))

  END

GO


SELECT dbo.fnPadNumber(1234567890.12,16)

-- 0001234567890.12
------------

-- T SQL computed column zero padding - sql generate alphanumeric sequence

USE tempdb; -- SQL Server 2008 T-SQL

CREATE TABLE Celebrity (

  ID           INT    IDENTITY ( 1 , 1 )    PRIMARY KEY,

  CelebrityID  AS 'CEL' + RIGHT('0000' + CAST( ID as varchar),5), -- computed column

  FirstName    VARCHAR(32),

  LastName     VARCHAR(32),

  ModifiedDate DATE    DEFAULT getdate())

GO


INSERT Celebrity

      (FirstName,

       LastName)

VALUES('Jennifer','Aniston'),

      ('Drew','Barrymore'),

      ('Diana','Princess of Wales'),

      ('Tom','Jones'),

      ('Lucille','Ball'),

      ('Frank','Sinatra'),

      ('Elvis','Presley')


SELECT * FROM   Celebrity

GO

-- CelebrityID is zero padded alphanumeric sequence

/* 

ID    CelebrityID       FirstName  LastName          ModifiedDate

1     CEL00001          Jennifer    Aniston          2012-07-04

2     CEL00002          Drew        Barrymore        2012-07-04

3     CEL00003          Diana       Princess of Wales 2012-07-04

4     CEL00004          Tom         Jones             2012-07-04

5     CEL00005          Lucille     Ball              2012-07-04

6     CEL00006          Frank       Sinatra          2012-07-04

7     CEL00007          Elvis       Presley          2012-07-04

*/

-- Cleanup demo

DROP TABLE Celebrity

GO
------------

-- SQL removing leading zeros when no spaces in string - trimming Leading Zeros

USE AdventureWorks2008;

DECLARE @NumberString varchar(16)='000000246'

SELECT REPLACE(LTRIM(REPLACE(@NumberString, '0', ' ')), ' ', '0')

-- 246

------------

-- SQL remove leading zeros - sql trim leading zeros - numeric test

DECLARE @StringWithLeadingZeros    VARCHAR(12) = '000000654321'

SELECT CAST(CAST(@StringWithLeadingZeros AS INT) AS VARCHAR(10))

WHERE ISNUMERIC (@StringWithLeadingZeros)=1

-- 654321

------------

-- LPAD &amp;amp; RPAD string scalar-valued user-defined functions (UDF)

USE AdventureWorks;

GO

-- Left pad string function

CREATE FUNCTION LPAD

               (@SourceString VARCHAR(MAX),

                @FinalLength  INT,

                @PadChar      CHAR(1))

RETURNS VARCHAR(MAX)

AS

  BEGIN

    RETURN

      (SELECT Replicate(@PadChar,@FinalLength - Len(@SourceString)) + @SourceString)

  END

GO


-- T-SQL Test left padding

SELECT LeftPaddedString = dbo.LPAD(Cast(84856 AS VARCHAR),12,'0')

GO

-- 000000084856


-- MSSQL right pad string function

CREATE FUNCTION RPAD

               (@SourceString VARCHAR(MAX),

                @FinalLength  INT,

                @PadChar      CHAR(1))

RETURNS VARCHAR(MAX)

AS

  BEGIN

    RETURN

      (SELECT @SourceString + Replicate(@PadChar,@FinalLength - Len(@SourceString)))

  END

GO


-- Test right padding

SELECT RightPaddedString = dbo.RPAD(Cast(84856 AS VARCHAR),12,'*')

GO

-- 84856*******

----------


-- Padding a money column with leading zeroes - sql convert leading zero

-- SQL convert money data type to string

SELECT PaddedUnitPrice = RIGHT(replicate('0',20) +

                         convert(varchar,UnitPrice,1), 20)

FROM Northwind.dbo.Products

/* Partial results


PaddedUnitPrice

00000000000000018.00

00000000000000019.00

00000000000000010.00

00000000000000022.00

*/


/**************** Zero padding other numeric data ****************/


-- SQL Server 2008 version featuring the LEFT function

-- SQL convert integer to text - convert integer to varchar

USE AdventureWorks2008;

DECLARE @InputNumber int = 522, @OutputLength tinyint = 12

DECLARE @PaddedString char(12)

SET @PaddedString = LEFT( replicate( '0', @OutputLength ),

    @OutputLength - len( @InputNumber ) ) + convert( varchar(12), @InputNumber)

SELECT PaddedNumber=@PaddedString

/* Result


PaddedNumber

000000000522

*/



-- SQL format currency and pad with leading spaces

-- SQL Server lpad to 9 characters

SELECT   TOP (3)  ProductName=Name,

                  Price=   CONVERT(char(9), ListPrice, 1)

FROM Production.Product

WHERE ListPrice &amp;gt; 0.0 ORDER BY Newid()

/*

ProductName                         Price

LL Touring Frame - Blue, 62           333.42

LL Road Seat Assembly                 133.34

Road-250 Red, 58                    2,443.35

*/

------------

-- Padding with zeroes in the middle of string

DECLARE @Number varchar(10)

SET @Number = '99999'

PRINT 'TRK' + REPLICATE('0', 12 - LEN(@Number)) + @Number

SELECT [Zero Padding]='TRK' + REPLICATE('0', 12 - LEN(@Number)) + @Number

-- Result: TRK000000099999


-- Applying the STUFF string function for zero padding

-- SQL convert integer data type to string

DECLARE @SerialNo int, @OutputSize tinyint

SET @OutputSize = 10

SET @SerialNo = 6543

SELECT PaddedSerialNo =  STUFF(replicate('0', @OutputSize),

    @OutputSize - len(@SerialNo)+1, len(@SerialNo), convert(varchar(9),@SerialNo))

-- Result: 0000006543

-- SQL pad integer with 0-s

-- SQL str function - numeric to character conversion

SELECT TOP 5

CAST(replace(str(ProductID,6),' ','0') AS char(6)) AS ProdID

FROM AdventureWorks.Production.Product

ORDER BY Name

/* Results

ProdID

000001

000879

000712

000003

000002

*/


-- SQL pad string with character

-- SQL create function

-- SQL user-defined function

CREATE FUNCTION dbo.fnLeftPadString (

      @Input VARCHAR(255),

      @PadChar CHAR(1),

      @LengthToPad TINYINT

      )

RETURNS VARCHAR(255) AS 

BEGIN

DECLARE @InputLen TINYINT

SET @InputLen = LEN(@Input)

RETURN

   CASE

      WHEN @InputLen &amp;lt; @LengthToPad

      THEN REPLICATE(@PadChar, @LengthToPad - @InputLen) + @Input

      ELSE @Input

   END -- CASE

END -- UDF

GO


-- SQL pad string – left padding - SQL left pad with asterisk

-- SQL check printing - SQL currency formatting

DECLARE @DollarAmount varchar(20)

SET @DollarAmount = '234.40'

SELECT PaddedString='$'+dbo.fnLeftPadString(@DollarAmount, '*', 10)

GO

-- Result: $****234.40


-- SQL currency formatting with asterisk-fill

DECLARE @Amount MONEY

SET @Amount = '3534.40'

SELECT CurrencyFormat = '$' + REPLACE(Convert(char(12),@Amount,1),' ','*')

-- $****3,534.40

SELECT      PaddedProductID =

                  dbo.fnLeftPadString (CONVERT(varchar, ProductID), '0', 6),

            ProductName=Name,

            ListPrice

FROM Production.Product

ORDER BY PaddedProductID

GO


/* Partial results


PaddedProductID         ProductName       ListPrice

000757                  Road-450 Red, 48  1457.99

000758                  Road-450 Red, 52  1457.99

000759                  Road-650 Red, 58  782.99

000760                  Road-650 Red, 60  782.99

000761                  Road-650 Red, 62  782.99

*/

----------

-- Generating tracking numbers

-- SQL pad zeroes

WITH cteSequence(SeqNo)

     AS (SELECT 1

         UNION ALL

         SELECT SeqNo + 1

         FROM   cteSequence

         WHERE  SeqNo &amp;lt; 1000000)

SELECT TOP 100 CAST(('TRK' + REPLICATE('0',

               7 - LEN(CAST(SeqNo AS VARCHAR(6)))) +

               CAST(SeqNo AS VARCHAR(6))) AS VARCHAR(10)) AS TrackingNo

FROM   cteSequence

OPTION (MAXRECURSION 0)

GO

/* Partial results


TrackingNo

TRK0000001

TRK0000002

TRK0000003

TRK0000004

TRK0000005

TRK0000006

TRK0000007

*/

----------

-- SQL server pad

-- SQL str function

-- SQL pad integer

-- SQL left pad

SELECT TOP (4) StaffName=LastName+', '+FirstName,

PaddedEmployeeID = REPLACE(STR(EmployeeID, 6, 0), ' ', '0')

FROM HumanResources.Employee e

INNER JOIN Person.Contact c

      ON e.ContactID = c.ContactID

ORDER BY NEWID()

/* Results


StaffName         PaddedEmployeeID

Dyck, Shelley     000214

Hines, Michael    000039

Ford, Jeffrey     000015

Caron, Rob        000168

*/


-- SQL asterisk padding

-- SQL pad with asterisk

-- SQL right pad

SELECT  TOP ( 2 * 2 )

              AddressID

            , City+REPLICATE('*', 20-len(City)) AS City

            , PostalCode

FROM AdventureWorks.Person.[Address]

WHERE LEN(City) &amp;lt;= 20

ORDER by NEWID()

GO

/*

AddressID   City                          PostalCode

13465       Imperial Beach******    91932

23217       Corvallis***********    97330

18548       Milwaukie***********    97222

24893       Goulburn************    2580

*/

------------

------------

-- SQL left pad any size string Alpha with any length string Beta

------------

-- SQL user-defined function - UDF - scalar-valued string function

-- T-SQL varchar(max)

USE AdventureWorks2008;

GO

CREATE FUNCTION fnMaxPad

               (@SourceString  VARCHAR(MAX),

                @PaddingString VARCHAR(MAX),

                @OutputLength  INT)

RETURNS VARCHAR(MAX)

AS

  BEGIN

    DECLARE  @WorkString VARCHAR(MAX) =

      ISNULL(REPLICATE(@PaddingString,@OutputLength - len(ISNULL(@SourceString,0))),

                            '') + @SourceString

    RETURN RIGHT(@WorkString, @OutputLength)

  END

GO


-- Execute UDF

SELECT TOP ( 5 ) [SQL Padding Demo] =

  dbo.fnMaxPad(CONVERT(VARCHAR,FLOOR(ListPrice)),'_/',21)

FROM     Production.Product

ORDER BY NEWID()

GO

/* Results


SQL Padding Demo

_/_/_/_/_/_/_/2443.00

/_/_/_/_/_/_/_/_/0.00

/_/_/_/_/_/_/_/147.00

/_/_/_/_/_/_/_/_/0.00

_/_/_/_/_/_/_/1003.00

*/

------------

-- SQL left pad unicode string Alpha with any length unicode string Beta

-- MSSQL pad international

-- SQL user-defined function - UDF - scalar-value function

-- T-SQL nvarchar(max)

USE AdventureWorks2008;

GO

CREATE FUNCTION fnMaxPadInternational

               (@SourceString  NVARCHAR(MAX),

                @PaddingString NVARCHAR(MAX),

                @OutputLength  INT)

RETURNS NVARCHAR(MAX)

AS

  BEGIN

    DECLARE  @WorkString NVARCHAR(MAX) =

      ISNULL(REPLICATE(@PaddingString,@OutputLength - len(ISNULL(@SourceString,0))),

                            '') + @SourceString

    

    RETURN RIGHT(@WorkString, @OutputLength)

  END

GO


-- Execute UDF

SELECT TOP ( 5 ) [SQL Padding Demo] =

dbo.fnMaxPadInternational(LEFT(Description,6),'_/',21)

FROM     Production.ProductDescription

ORDER BY NEWID()

GO

/* Results


SQL Padding Demo

/_/_/_/_/_/_/_/ล้อ ที่

/_/_/_/_/_/_/_/Roue d

/_/_/_/_/_/_/_/شوكة ط

/_/_/_/_/_/_/_/Each f

/_/_/_/_/_/_/_/Jeu de

*/

------------
&lt;/pre&gt;&lt;div class="MsoNormal"&gt;Reference from sqlusa.com&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-2363755376885264898?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ACoydUFzFg_F-cr6VV6PBNA5w74/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ACoydUFzFg_F-cr6VV6PBNA5w74/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ACoydUFzFg_F-cr6VV6PBNA5w74/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ACoydUFzFg_F-cr6VV6PBNA5w74/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/zgWrZ9_DNbc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/2363755376885264898/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2009/12/how-to-pad-numeric-type-column-with.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/2363755376885264898?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/2363755376885264898?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/zgWrZ9_DNbc/how-to-pad-numeric-type-column-with.html" title="How to pad a numeric type column with leading zeros?" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2009/12/how-to-pad-numeric-type-column-with.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AMSHw5eCp7ImA9WxBSEkw.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-6853005029946194044</id><published>2009-12-19T01:33:00.000-08:00</published><updated>2009-12-19T01:43:09.220-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-19T01:43:09.220-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>How to configure SQL Server 2005 to allow remote connections?</title><content type="html">To configure SQL Server 2005 to allow remote connections, complete all the following steps.&lt;br /&gt;
• Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer.&lt;br /&gt;
• Turn on the SQL Server Browser service.&lt;br /&gt;
• Configure the firewall to allow network traffic that is related to SQL Server and to the SQL Server Browser service.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Enable remote connections for SQL Server 2005 Express&lt;/h3&gt;1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.&lt;br /&gt;
2. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.&lt;br /&gt;
3. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply.&lt;br /&gt;
Note Click OK when you receive the following message:&lt;br /&gt;
Changes to Connection Settings will not take effect until you restart the Database Engine service.&lt;br /&gt;
4. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop. wait until the MSSQLSERVER service stops, and then click &lt;b&gt;Start&lt;/b&gt; to restart the MSSQLSERVER service.&lt;br /&gt;
&lt;h3&gt;Enable the SQL Server Browser service&lt;/h3&gt;1.Click &lt;b&gt;Start&lt;/b&gt;, point to &lt;b&gt;Programs&lt;/b&gt;, point to &lt;b&gt;Microsoft SQL Server 2005&lt;/b&gt;, point to &lt;b&gt;Configuration Tools&lt;/b&gt;, and then click &lt;b&gt;SQL Server Surface Area Configuration&lt;/b&gt;.&lt;br /&gt;
2.On the &lt;b&gt;SQL Server 2005 Surface Area Configuration&lt;/b&gt; page, click &lt;b&gt;Surface Area Configuration for Services and Connections&lt;/b&gt;.&lt;br /&gt;
3.On the &lt;b&gt;Surface Area Configuration for Services and Connections&lt;/b&gt; page, click &lt;b&gt;SQL Server Browser&lt;/b&gt;, click &lt;b&gt;Automatic&lt;/b&gt; for &lt;b&gt;Startup type&lt;/b&gt;, and then click &lt;b&gt;Apply&lt;/b&gt;.&lt;br /&gt;
&lt;b&gt;Note&lt;/b&gt; When you click the &lt;b&gt;Automatic&lt;/b&gt; option, the SQL Server Browser service starts automatically every time that you start Microsoft Windows.&lt;br /&gt;
4.Click &lt;b&gt;Start&lt;/b&gt;, and then click &lt;b&gt;OK&lt;/b&gt;.&lt;br /&gt;
&lt;h3&gt;Create exceptions in Windows Firewall&lt;/h3&gt;SQL Server 2005 uses an instance ID as part of the path when you install its program files. To create an exception for each instance of SQL Server, you must identify the correct instance ID. To obtain an instance ID, follow these steps:&lt;br /&gt;
1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Configuration Manager.&lt;br /&gt;
2. In SQL Server Configuration Manager, click the SQL Server Browser service in the right pane, right-click the instance name in the main window, and then click Properties.&lt;br /&gt;
3. On the SQL Server Browser Properties page, click the Advanced tab, locate the instance ID in the property list, and then click OK.&lt;br /&gt;
To open Windows Firewall, click Start, click Run, type firewall.cpl, and then click OK.&lt;br /&gt;
Create an exception for SQL Server 2005 in Windows Firewall&lt;br /&gt;
To create an exception for SQL Server 2005 in Windows Firewall, follow these steps:&lt;br /&gt;
1. In Windows Firewall, click the Exceptions tab, and then click Add Program.&lt;br /&gt;
2. In the Add a Program window, click Browse.&lt;br /&gt;
3. Click the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe executable program, click Open, and then click OK.&lt;br /&gt;
Note The path may be different depending on where SQL Server 2005 is installed. MSSQL.1 is a placeholder for the instance ID that you obtained in step 3 of the previous procedure.&lt;br /&gt;
4. Repeat steps 1 through 3 for each instance of SQL Server 2005 that needs an exception.&lt;br /&gt;
Create an exception for the SQL Server Browser service in Windows Firewall&lt;br /&gt;
To create an exception for the SQL Server Browser service in Windows Firewall, follow these steps:&lt;br /&gt;
1. In Windows Firewall, click the Exceptions tab, and then click Add Program.&lt;br /&gt;
2. In the Add a Program window, click Browse.&lt;br /&gt;
3. Click the C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe executable program, click Open, and then click OK.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
Hope this&amp;nbsp;helps everyone.&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-6853005029946194044?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/orKsxfC3ixXAQ3VcCJM_QZ9PrBw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/orKsxfC3ixXAQ3VcCJM_QZ9PrBw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/orKsxfC3ixXAQ3VcCJM_QZ9PrBw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/orKsxfC3ixXAQ3VcCJM_QZ9PrBw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/lukL9GNCWmM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/6853005029946194044/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2009/12/how-to-configure-sql-server-2005-to.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/6853005029946194044?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/6853005029946194044?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/lukL9GNCWmM/how-to-configure-sql-server-2005-to.html" title="How to configure SQL Server 2005 to allow remote connections?" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2009/12/how-to-configure-sql-server-2005-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YEQn88eCp7ImA9WxBWGE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-8705542601113003202</id><published>2009-12-18T04:34:00.000-08:00</published><updated>2010-02-10T04:31:43.170-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T04:31:43.170-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.Net" /><title>Encryption &amp; Decryption : ASCII encoding</title><content type="html">The GetByteCount method determines how many bytes result in encoding a set of Unicode characters, and the GetBytes method performs the actual encoding.&lt;br /&gt;
&lt;br /&gt;
Likewise, the GetCharCount method determines how many characters result in decoding a sequence of bytes, and the GetChars and GetString methods perform the actual decoding.&lt;br /&gt;
&lt;br /&gt;
When selecting the ASCII encoding for your applications, consider the following:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * The ASCII encoding is usually appropriate for protocols that require ASCII.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * If your application requires 8-bit encoding, the UTF-8 encoding is recommended over the ASCII encoding. For the characters 0-7F, the results are identical, but use&lt;br /&gt;
&lt;br /&gt;
of UTF-8 avoids data loss by allowing representation of all Unicode characters that are representable. Note that the ASCII encoding has an 8th bit ambiguity that can allow malicious use, but the UTF-8 encoding removes ambiguity about the 8th bit.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; * Previous versions of .NET Framework allowed spoofing by merely ignoring the 8th bit. The current version has been changed so that non-ASCII code points fall back during the decoding of bytes.&lt;br /&gt;
&lt;br /&gt;
——————————————————————&lt;br /&gt;
&lt;b&gt;Example of ASCII encoding&lt;/b&gt;&lt;br /&gt;
——————————————————————&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SecurityClass.cs&lt;/b&gt;&lt;br /&gt;
————————–&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;public static string EnryptString(string strEncrypted)
{
byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted);
string encryptedConnectionString = Convert.ToBase64String(b);
return encryptedConnectionString;
}

public static string DecryptString(string encrString)
{
byte[] b = Convert.FromBase64String(encrString);
string decryptedConnectionString = System.Text.ASCIIEncoding.ASCII.GetString(b);
return decryptedConnectionString;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Default.aspx.cs&lt;/b&gt;&lt;br /&gt;
———————&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Password = “SandeepMRamani”;
lblOriginal.Text = Password;
lblEncryption.Text = SecurityClass.EnryptString(Password);
lblDecryption.Text = SecurityClass.DecryptString(lblEncryption.Text);
}
}
&lt;/pre&gt;Default.aspx&lt;br /&gt;
——————&lt;br /&gt;
&lt;pre class="brush:html"&gt;&amp;lt;div align=”center” style=”font-size:xx-large;”&amp;gt;
&amp;lt;h1&amp;gt; Encryption / Decryption Example &amp;lt;/h1&amp;gt;
&amp;lt;hr /&amp;gt;

Original String :
&amp;lt;asp:Label ID=”lblOriginal” style=”font-weight:bolder;” runat=”server” Text=”"&amp;gt;&amp;lt;/asp:Label&amp;gt;
&amp;lt;br /&amp;gt;
Encrypted Text :
&amp;lt;asp:Label ID=”lblEncryption” style=”font-weight:bolder;” runat=”server” Text=”"&amp;gt;&amp;lt;/asp:Label&amp;gt;
&amp;lt;br /&amp;gt;
Decrypted Text :
&amp;lt;asp:Label ID=”lblDecryption” style=”font-weight:bolder;” runat=”server” Text=”"&amp;gt;&amp;lt;/asp:Label&amp;gt;
&amp;lt;hr /&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
Happy programming&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-8705542601113003202?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/l0P2FH0BPbNduluikEqLS5lGOKo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/l0P2FH0BPbNduluikEqLS5lGOKo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/l0P2FH0BPbNduluikEqLS5lGOKo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/l0P2FH0BPbNduluikEqLS5lGOKo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/8TxctOr9CtA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/8705542601113003202/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2009/12/encryption-decryption-ascii-encoding.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/8705542601113003202?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/8705542601113003202?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/8TxctOr9CtA/encryption-decryption-ascii-encoding.html" title="Encryption &amp; Decryption : ASCII encoding" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2009/12/encryption-decryption-ascii-encoding.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMCQ3k7fyp7ImA9WxBSEU8.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-1153579822507611833</id><published>2009-12-18T00:21:00.000-08:00</published><updated>2009-12-18T00:21:02.707-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-18T00:21:02.707-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>Differences between varchar and nvarchar in SQL Server</title><content type="html">=&amp;gt;SQL Server 2000 and SQL          Server 7, a row cannot exceed 8000 bytes in size. This means that a VARBINARY          column can only store 8000 bytes (assuming it is the only column in a          table), a VARCHAR column can store up to 8000 characters and an NVARCHAR          column can store up to 4000 characters (2 bytes per unicode character).          This limitation stems from the 8 KB internal page size SQL Server uses          to save data to disk.         &lt;br /&gt;
To store more data in a single column, you          needed to use the TEXT, NTEXT, or IMAGE data types (BLOBs) which are          stored in a collection of 8 KB data pages that are separate from the          data pages that store the other data in the same table. These data pages          are arranged in a B-tree structure. BLOBs are hard to work with and          manipulate. They cannot be used as variables in a procedure or a          function and they cannot be used inside string functions such as          REPLACE, CHARINDEX or SUBSTRING. In most cases, you have to use READTEXT,          WRITETEXT, and UPDATETEXT commands to manipulate BLOBs.&lt;br /&gt;
&lt;br /&gt;
To solve this problem, Microsoft introduced the VARCHAR(MAX),&amp;nbsp; NVARCHAR(MAX),          and VARBINARY(MAX) data types in SQL Server 2005. These data types can          hold the same amount of data BLOBs can hold (2 GB) and they are stored          in the same type of data pages used for other data types. When data in a          MAX data type exceeds 8 KB, an over-flow page is used. SQL Server 2005          automatically assigns an over-flow indicator to the page and knows how          to manipulate data rows the same way it manipulates other data types.          You can declare variables of MAX data types inside a stored procedure or          function and even pass them as variables. You can also use them inside          string functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="a3"&gt; The broad range of data types in SQL Server can sometimes throw people through a loop, especially when the data types seem to be highly interchangeable. Two in particular that constantly spark questions are &lt;b&gt;VARCHAR&lt;/b&gt; and &lt;b&gt;NVARCHAR&lt;/b&gt;: what's the difference between the two, and how important is the difference?  VARCHAR is an abbreviation for &lt;b&gt;variable-length character string&lt;/b&gt;. It's a string of text characters that can be as large as the page size for the database table holding the column in question. The size for a table page is 8,196 bytes, and no one row in a table can be more than 8,060 characters. This in turn limits the maximum size of a VARCHAR to 8,000 bytes.&lt;br /&gt;
The "N" in NVARCHAR means &lt;b&gt;uNicode&lt;/b&gt;. Essentially, NVARCHAR is nothing more than a VARCHAR that supports two-byte characters. The most common use for this sort of thing is to store character data that is a mixture of English and non-English symbols — in my case, English and Japanese.&lt;br /&gt;
The key difference between the two data types is how they're stored. VARCHAR is stored as regular 8-bit data. But NVARCHAR strings are stored in the database as UTF-16 — 16 bits or two bytes per character, all the time — and converted to whatever codepage is being used by the database connection on output (typically UTF-8). That said, NVARCHAR strings have the same length restrictions as their VARCHAR cousins — 8,000 bytes. However, since NVARCHARs use two bytes for each character, that means a given NVARCHAR can only hold 4,000 characters (not bytes) maximum. So, the amount of storage needed for NVARCHAR entities is going to be twice whatever you'd allocate for a plain old VARCHAR.&lt;br /&gt;
Because of this, some people may not want to use NVARCHAR universally, and may want to fall back on VARCHAR — which takes up less space per row — whenever possible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-1153579822507611833?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fm1UlnBC9y8Qs6I6NM1VrAtIGrU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fm1UlnBC9y8Qs6I6NM1VrAtIGrU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fm1UlnBC9y8Qs6I6NM1VrAtIGrU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fm1UlnBC9y8Qs6I6NM1VrAtIGrU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/aafAZX4Wqxs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/1153579822507611833/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2009/12/differences-between-varchar-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/1153579822507611833?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/1153579822507611833?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/aafAZX4Wqxs/differences-between-varchar-and.html" title="Differences between varchar and nvarchar in SQL Server" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2009/12/differences-between-varchar-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UMRn4yeip7ImA9WxBWGE0.&quot;"><id>tag:blogger.com,1999:blog-6293717301516478624.post-5291359505445461551</id><published>2009-12-16T22:01:00.000-08:00</published><updated>2010-02-10T04:34:47.092-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T04:34:47.092-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JQuery" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.Net" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Java Script" /><title>How to dynamically adjust an iframe’s height?</title><content type="html">I was looking to display content of the other aspx page inside iframe but i wasnt able to adjust the height of the iframe. so try out this solution to resolve it.&lt;br /&gt;
&lt;br /&gt;
Insert iframe on page&lt;br /&gt;
&lt;pre class="brush:html"&gt;&amp;nbsp;&amp;nbsp;&lt;b&gt; &amp;lt;iframe scrolling='no' frameborder='0' id='frmid' src=’getad.aspx'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; onload='javascript:resizeIframe(this);'&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;lt;/iframe&amp;gt;
&lt;/b&gt;&lt;/pre&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Use this javascript to resize iframe based on the height &amp;amp; width of child page&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:js"&gt;&lt;b&gt;&amp;lt;script language="javascript" type="text/javascript"&amp;gt;
&amp;nbsp;function resizeIframe(obj)
&amp;nbsp;{
&amp;nbsp;&amp;nbsp; obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
&amp;nbsp;&amp;nbsp; obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
&amp;nbsp;}
&amp;nbsp;&amp;lt;/script&amp;gt;
&lt;/b&gt;&lt;/pre&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
What does this code do? When the body of the parent frame loads, it looks up the document element “childframe” which corresponds to the iframe. Then the page calls a function resizeFrame(). The function sets the height of the frame to be the scrollHeight, which effectively removes the scrollbar.&lt;br /&gt;
&lt;br /&gt;
happy programming!&lt;div class="blogger-post-footer"&gt;Yogesh's Feed&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6293717301516478624-5291359505445461551?l=yogeshyrbyogi.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Et1KdPHORRtQZfKh8IZX_wRk1qQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Et1KdPHORRtQZfKh8IZX_wRk1qQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Et1KdPHORRtQZfKh8IZX_wRk1qQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Et1KdPHORRtQZfKh8IZX_wRk1qQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/jsbM/~4/mbyD9t9FTSs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://yogeshyrbyogi.blogspot.com/feeds/5291359505445461551/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://yogeshyrbyogi.blogspot.com/2009/12/how-to-dynamically-adjust-iframes.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/5291359505445461551?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6293717301516478624/posts/default/5291359505445461551?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/jsbM/~3/mbyD9t9FTSs/how-to-dynamically-adjust-iframes.html" title="How to dynamically adjust an iframe’s height?" /><author><name>Yogesh Bhadauriya</name><uri>http://www.blogger.com/profile/13293603717851986272</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://yogeshyrbyogi.blogspot.com/2009/12/how-to-dynamically-adjust-iframes.html</feedburner:origLink></entry></feed>

