<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1643476320867117891</id><updated>2011-11-28T06:09:57.047+05:30</updated><category term='C#'/><category term='LINQ'/><category term='Payment Gateway'/><category term='Discussion'/><category term='Regular Expressions'/><category term='SQL Server'/><category term='Excel Sheet Import/Export'/><category term='Interview Tips'/><category term='XML'/><category term='JavaScript'/><category term='Error Message and Resolution'/><category term='Articles'/><category term='Ajax'/><category term='ASP.NET'/><category term='Import/Export CSV'/><title type='text'>Dot Net Free Code Snippets</title><subtitle type='html'>Microsoft Technologies, ASP.NET, C#, VB.NET, SQL Server, JavaScript, XML, XSLT, Import/Export Excel and csv files, Payment Gateway Integration, Ajax.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>74</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-803844811137487886</id><published>2011-09-08T10:56:00.001+05:30</published><updated>2011-09-08T11:00:09.778+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Replace A String From The Data In The Database</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;p&gt;Following SQL script will help to replace a particular string from all user defined tables in the database.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;DECLARE @TEMP TABLE(tabname VARCHAR(100)) &lt;br /&gt;DECLARE @COUNT INT, @tabname VARCHAR(100)&lt;br /&gt;DECLARE @ColTemp TABLE(colName VARCHAR(100))&lt;br /&gt;DECLARE @ColCount INT, @ColName VARCHAR(100)&lt;br /&gt;DECLARE @SQLQuery VARCHAR(1000), @ReplaceChar VARCHAR(10), @ReplaceTo VARCHAR(10)&lt;br /&gt;&lt;br /&gt;SET @ReplaceChar='-'&lt;br /&gt;SET @ReplaceTo = '?'&lt;br /&gt;&lt;br /&gt;INSERT INTO @TEMP (tabname)&lt;br /&gt;(SELECT [name] FROm SYS.TABLES WHERE name='tblFormula')&lt;br /&gt;&lt;br /&gt;SELECT @COUNT=Count(*) FROM @TEMP&lt;br /&gt;&lt;br /&gt;WHILE @COUNT&amp;gt;0&lt;br /&gt;BEGIN&lt;br /&gt;SELECT TOP 1 @tabname=tabname FROM @TEMP&lt;br /&gt;&lt;br /&gt;INSERT INTO @ColTemp (colName)&lt;br /&gt;(SELECT Top 1 [name] FROm SYS.COLUMNS WHERE [Object_id]=Object_ID(@tabname))&lt;br /&gt;&lt;br /&gt;SELECT @ColCount=Count(*) FROM @ColTemp&lt;br /&gt;WHILE @COLCount&amp;gt;0&lt;br /&gt;BEGIN&lt;br /&gt;SELECT TOP 1 @ColName=ColName FROM @ColTemp&lt;br /&gt;&lt;br /&gt;SET @SQLQuery = 'UPDATE ' + @tabname + ' SET ' + @ColName + '= REPLACE(' + @ColName + ', ''' + @ReplaceChar + ''','''+ @ReplaceTo + ''')'&lt;br /&gt;&lt;br /&gt;PRINT @SQLQuery&lt;br /&gt;&lt;br /&gt;DELETE FROM @ColTemp WHERE ColName=@ColName&lt;br /&gt;SELECT @ColCount=Count(*) FROM @ColTemp&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;DELETE FROM @TEMP WHERE tabname=@tabname&lt;br /&gt;SELECT @COUNT=Count(*) FROM @TEMP&lt;br /&gt;END&lt;br /&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-803844811137487886?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/803844811137487886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=803844811137487886&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/803844811137487886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/803844811137487886'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2011/09/replace-string-from-data-in-database.html' title='Replace A String From The Data In The Database'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6685025124123288375</id><published>2011-07-19T15:39:00.000+05:30</published><updated>2011-07-19T15:39:27.106+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Get The First And Last Working Day Of Each Month For the Given Year</title><content type='html'>This store procedure will help to get the first and last working day of each month in a given year.&lt;br /&gt;&lt;blockquote&gt;DECLARE @Year INT&lt;br /&gt;SET @Year=2011&lt;br /&gt;&lt;br /&gt;DECLARE @FirstDate DateTime,@LastDate DATETIME, @DayofWeek INT&lt;br /&gt;DECLARE @FirstWorkingDay DATETIME, @LastWorkingDay DATETIME&lt;br /&gt;&lt;br /&gt;SET @FirstDate = '01-01-'+CONVERT(VARCHAR(4),@Year)&lt;br /&gt;SET DATEFIRST 1&lt;br /&gt;&lt;br /&gt;WHILE (MONTH(@FirstDate) &amp;lt;=12 AND YEAR(@FirstDate)=@Year)&lt;br /&gt;BEGIN&lt;br /&gt;SET @DayofWeek = DATEPART(weekday,@FirstDate)&lt;br /&gt;--First working day of the month&lt;br /&gt;IF(@DayofWeek = 7)&lt;br /&gt;SET @FirstWorkingDay= @FirstDate+1&lt;br /&gt;ELSE IF (@DayofWeek = 6)&lt;br /&gt;SET @FirstWorkingDay = @FirstDate+2&lt;br /&gt;ELSE &lt;br /&gt;SET @FirstWorkingDay = @FirstDate&lt;br /&gt;&lt;br /&gt;--Get Last working day of the month&lt;br /&gt;SET @LastDate=DATEADD(mm,1,@FirstDate)-1&lt;br /&gt;SET @DayofWeek = DATEPART(weekday,@LastDate)&lt;br /&gt;IF(@DayofWeek = 7)&lt;br /&gt;SET @LastWorkingDay = @LastDate-2&lt;br /&gt;ELSE IF (@DayofWeek = 6)&lt;br /&gt;SET @LastWorkingDay = @LastDate-1&lt;br /&gt;ELSE &lt;br /&gt;SET @LastWorkingDay = @LastDate&lt;br /&gt;&lt;br /&gt;SELECT @FirstWorkingDay AS FirstDay, @LastWorkingDay AS 'Last Day'&lt;br /&gt;SET @FirstDate=DATEADD(mm,1,@FirstDate)&lt;br /&gt;END&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6685025124123288375?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6685025124123288375/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6685025124123288375&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6685025124123288375'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6685025124123288375'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2011/07/get-first-and-last-working-day-of-each.html' title='Get The First And Last Working Day Of Each Month For the Given Year'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6684284453918229823</id><published>2010-07-30T12:28:00.000+05:30</published><updated>2010-07-30T12:28:30.317+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><title type='text'>AutoComplete functionality Using Ajax Control Toolkit</title><content type='html'>This code snippet will help user to implement autocomplete functionality and also help to customize the autocomplete functioanlity. Like pass optional parameters while getting suggestions and disable tab button and execute some event on selection.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Sample.aspx:&lt;/b&gt;&lt;br /&gt;&lt;blockquote&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;        var KeyID;&lt;br /&gt;&lt;br /&gt;        function LoadAutoComplete(source, eventArgs) {&lt;br /&gt;            SetContextKeyValue();&lt;br /&gt;        }&lt;br /&gt;        function DoPostBack(source, eventArgs) {&lt;br /&gt;            KeyCheck(source);&lt;br /&gt;            if (KeyID != 9)&lt;br /&gt;             __doPostBack('lnkSubmit', ''); //Replace this with your script.&lt;br /&gt;            else&lt;br /&gt;                document.getElementById('&amp;lt;%=txtLastName.ClientID %&amp;gt;').value = source._currentPrefix&lt;br /&gt;        }&lt;br /&gt;        function KeyCheck(e) {&lt;br /&gt;&lt;br /&gt;            KeyID = (window.event) ? event.keyCode : e.keyCode;&lt;br /&gt;        }&lt;br /&gt;        function SetContextKeyValue() {&lt;br /&gt;            var firstname = document.getElementById('&amp;lt;%=txtFirstName.ClientID %&amp;gt;').value&lt;br /&gt;            var location = document.getElementById('&amp;lt;%=drLocation.ClientID %&amp;gt;').value&lt;br /&gt;            if (location == "0")&lt;br /&gt;                location = ""&lt;br /&gt;                IncludeWOPhone="1"&lt;br /&gt;            varFilters = firstname + "~" + &lt;br /&gt;            $find('acLastName').set_contextKey(varFilters);&lt;br /&gt;        }&lt;br /&gt;    &amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;asp:TextBox ID="txtLastName" TabIndex="1" runat="server" MaxLength="50"&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;                                                                &amp;lt;ajaxToolkit:AutoCompleteExtender runat="server" ID="acLastName" TargetControlID="txtLastName"                                                                   ContextKey="testValue"  UseContextKey="true" ServicePath="../AutoComplete.asmx" ServiceMethod="GetLastName"                                                                    MinimumPrefixLength="3" OnClientItemSelected="DoPostBack" CompletionInterval="50"                                                                     EnableCaching="false" CompletionSetCount="10" CompletionListCssClass="ac_completionListElement" OnClientPopulating="LoadAutoComplete"                                                                    CompletionListItemCssClass="ac_listItem" CompletionListHighlightedItemCssClass="ac_highlightedListItem"&amp;gt;                                                                &amp;lt;/ajaxToolkit:AutoCompleteExtender&amp;gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;p&gt;In the above AutocompleteExtender control I have used properties ContextKey &amp; UseContextKey. The purpose of these properties is to pass optional parameters to filter the records that we are going to populate in auto complete list.&lt;br /&gt;If we want to pass optional parameter then we need to set UseContextKey=”True”. By default value of UseContextKey is False. And in ContextKay property we can pass the filter values.&lt;br /&gt;We can also set these values dynamically using OnClientPopulating event of AutocompleteExtender.&lt;br /&gt;In this event I am calling a JavaScript method “LoadAutoComplete” and within this method I am calling “SetContextKeyValue” to set the ContextKey value at run time.&lt;br /&gt;I have also added one more customization in this code is disable item selection on click of Tab button click and execute some code on selection (Click of enter button or mouse click). I have used OnClientItemSelected event of AutocompleteExtender. And call a method to check if the key pressed is Tab key then do nothing otherwise redirect to next form using __doPostBack.&lt;br /&gt;&lt;/p&gt;&lt;b&gt;AutoComplete.asmx.vb&lt;/b&gt;&lt;br /&gt;&lt;blockquote&gt;Imports System.Web&lt;br /&gt;Imports System.Web.Services&lt;br /&gt;Imports System.Web.Services.Protocols&lt;br /&gt;Imports System.ComponentModel&lt;br /&gt;&amp;lt;System.Web.Script.Services.ScriptService()&amp;gt; _&lt;br /&gt;&amp;lt;WebService(Namespace:="http://tempuri.org/")&amp;gt; _&lt;br /&gt;&amp;lt;WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&amp;gt; _&lt;br /&gt;&amp;lt;Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()&amp;gt; _&lt;br /&gt;&lt;br /&gt;Public Class AutoComplete   Inherits System.Web.Services.WebService&lt;br /&gt;&lt;br /&gt;    &amp;lt;WebMethod()&amp;gt; _&lt;br /&gt;    Public Function GetLastName(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()&lt;br /&gt;        Dim _nameList As New Search&lt;br /&gt;   // Call your Own Method Here To get the Result in String Array&lt;br /&gt;        Return GetNameList(prefixText, count, contextKey)&lt;br /&gt;&lt;br /&gt;    End Function&lt;br /&gt;End Class&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6684284453918229823?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6684284453918229823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6684284453918229823&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6684284453918229823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6684284453918229823'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2010/07/autocomplete-functionality-using-ajax.html' title='AutoComplete functionality Using Ajax Control Toolkit'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2388207704571683491</id><published>2010-07-30T11:55:00.000+05:30</published><updated>2010-07-30T11:55:06.137+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Error Message and Resolution'/><title type='text'>That assembly does not allow partially trusted callers</title><content type='html'>Solution for error:&lt;br /&gt;Execption Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_Kp--fzJWFmc/TFJt0Jl9IEI/AAAAAAAAAXs/XtVemhUu7M4/s1600/err1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" bx="true" src="http://2.bp.blogspot.com/_Kp--fzJWFmc/TFJt0Jl9IEI/AAAAAAAAAXs/XtVemhUu7M4/s320/err1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;Check if the trust level is set to Medium then either remove this tag from web.config file or change it to Full&lt;br /&gt;as:&lt;br /&gt;&lt;blockquote&gt;&amp;lt;trust level="Full" /&amp;gt;&lt;/blockquote&gt;&lt;div align="left" class="separator" style="clear: both;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2388207704571683491?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2388207704571683491/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2388207704571683491&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2388207704571683491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2388207704571683491'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2010/07/that-assembly-does-not-allow-partially.html' title='That assembly does not allow partially trusted callers'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_Kp--fzJWFmc/TFJt0Jl9IEI/AAAAAAAAAXs/XtVemhUu7M4/s72-c/err1.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6092152464135005269</id><published>2009-12-02T11:40:00.000+05:30</published><updated>2009-12-02T11:40:22.147+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Get Feed Subscriber Count For Given Feed Burner URL</title><content type='html'>When we send a request on  the following url https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri= then the XML data will be returned as a XML.&lt;br /&gt;&lt;br /&gt;This is sample XML retured from feed burner:&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;&amp;lt;statuses type="array"&amp;gt;&lt;br /&gt;&amp;lt;status&amp;gt;&lt;br /&gt;&amp;lt;created_at&amp;gt;Tue Oct 27 16:44:10 +0000 2009&amp;lt;/created_at&amp;gt;&lt;br /&gt;&amp;lt;id&amp;gt;5204855334&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;lt;text&amp;gt;&lt;br /&gt;http://bit.ly/oUB92 Reading: Create Script File For Each Store Procedure And Save into Seperate SQL File For Each Store Procedure&lt;br /&gt;&amp;lt;/text&amp;gt;&lt;br /&gt;&amp;lt;source&amp;gt;web&amp;lt;/source&amp;gt;&lt;br /&gt;&amp;lt;truncated&amp;gt;false&amp;lt;/truncated&amp;gt;&lt;br /&gt;&amp;lt;in_reply_to_status_id/&amp;gt;&lt;br /&gt;&amp;lt;in_reply_to_user_id/&amp;gt;&lt;br /&gt;&amp;lt;favorited&amp;gt;false&amp;lt;/favorited&amp;gt;&lt;br /&gt;&amp;lt;in_reply_to_screen_name/&amp;gt;&lt;br /&gt;&amp;lt;user&amp;gt;&lt;br /&gt;&amp;lt;id&amp;gt;28538625&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;lt;name&amp;gt;Lakhan Pal Garg&amp;lt;/name&amp;gt;&lt;br /&gt;&amp;lt;screen_name&amp;gt;lakhangarg&amp;lt;/screen_name&amp;gt;&lt;br /&gt;&amp;lt;location/&amp;gt;&lt;br /&gt;&amp;lt;description/&amp;gt;&lt;br /&gt;&amp;lt;profile_image_url&amp;gt;&lt;br /&gt;http://a1.twimg.com/profile_images/319559736/PhotoFunia-19dab_normal.jpg&lt;br /&gt;&amp;lt;/profile_image_url&amp;gt;&lt;br /&gt;&amp;lt;url&amp;gt;http://lakhangarg.blogspot.com/&amp;lt;/url&amp;gt;&lt;br /&gt;&amp;lt;protected&amp;gt;false&amp;lt;/protected&amp;gt;&lt;br /&gt;&amp;lt;followers_count&amp;gt;16&amp;lt;/followers_count&amp;gt;&lt;br /&gt;&amp;lt;profile_background_color&amp;gt;9ae4e8&amp;lt;/profile_background_color&amp;gt;&lt;br /&gt;&amp;lt;profile_text_color&amp;gt;000000&amp;lt;/profile_text_color&amp;gt;&lt;br /&gt;&amp;lt;profile_link_color&amp;gt;0000ff&amp;lt;/profile_link_color&amp;gt;&lt;br /&gt;&amp;lt;profile_sidebar_fill_color&amp;gt;e0ff92&amp;lt;/profile_sidebar_fill_color&amp;gt;&lt;br /&gt;&amp;lt;profile_sidebar_border_color&amp;gt;87bc44&amp;lt;/profile_sidebar_border_color&amp;gt;&lt;br /&gt;&amp;lt;friends_count&amp;gt;15&amp;lt;/friends_count&amp;gt;&lt;br /&gt;&amp;lt;created_at&amp;gt;Fri Apr 03 10:39:09 +0000 2009&amp;lt;/created_at&amp;gt;&lt;br /&gt;&amp;lt;favourites_count&amp;gt;0&amp;lt;/favourites_count&amp;gt;&lt;br /&gt;&amp;lt;utc_offset&amp;gt;-36000&amp;lt;/utc_offset&amp;gt;&lt;br /&gt;&amp;lt;time_zone&amp;gt;Hawaii&amp;lt;/time_zone&amp;gt;&lt;br /&gt;&amp;lt;profile_background_image_url&amp;gt;&lt;br /&gt;http://s.twimg.com/a/1258070043/images/themes/theme1/bg.png&lt;br /&gt;&amp;lt;/profile_background_image_url&amp;gt;&lt;br /&gt;&amp;lt;profile_background_tile&amp;gt;false&amp;lt;/profile_background_tile&amp;gt;&lt;br /&gt;&amp;lt;statuses_count&amp;gt;12&amp;lt;/statuses_count&amp;gt;&lt;br /&gt;&amp;lt;notifications/&amp;gt;&lt;br /&gt;&amp;lt;geo_enabled&amp;gt;false&amp;lt;/geo_enabled&amp;gt;&lt;br /&gt;&amp;lt;verified&amp;gt;false&amp;lt;/verified&amp;gt;&lt;br /&gt;&amp;lt;following/&amp;gt;&lt;br /&gt;&amp;lt;/user&amp;gt;&lt;br /&gt;&amp;lt;geo/&amp;gt;&lt;br /&gt;&amp;lt;/status&amp;gt;&lt;br /&gt;&amp;lt;/statuses&amp;gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;b&gt;Sample code to get the follower count from the XML data is:&lt;/b&gt;&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;private static string GetTwitterFollowers(string TwitterURL)&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;if (TwitterURL != "")&lt;br /&gt;{&lt;br /&gt;TwitterURL = TwitterURL.Substring(TwitterURL.LastIndexOf('/') + 1);&lt;br /&gt;Uri uri = new Uri("http://twitter.com/statuses/user_timeline/" + TwitterURL + ".xml?count=1");&lt;br /&gt;HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);&lt;br /&gt;req.UserAgent = "Get Content";&lt;br /&gt;WebResponse resp = req.GetResponse();&lt;br /&gt;Stream stream = resp.GetResponseStream();&lt;br /&gt;StreamReader sr = new StreamReader(stream);&lt;br /&gt;string s = sr.ReadToEnd();&lt;br /&gt;System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();&lt;br /&gt;xDoc.LoadXml(s);&lt;br /&gt;string FollowerCount = xDoc.GetElementsByTagName("followers_count").Item(0).InnerText;&lt;br /&gt;if (FollowerCount == "")&lt;br /&gt;FollowerCount = "0";&lt;br /&gt;return FollowerCount;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;return "0";&lt;br /&gt;}&lt;br /&gt;catch&lt;br /&gt;{&lt;br /&gt;return "0";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6092152464135005269?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6092152464135005269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6092152464135005269&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6092152464135005269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6092152464135005269'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/12/get-feed-subscriber-count-for-given.html' title='Get Feed Subscriber Count For Given Feed Burner URL'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8574296770627744703</id><published>2009-12-01T15:37:00.000+05:30</published><updated>2009-12-01T15:37:32.699+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Code To Find Number of Sunday for the given Month</title><content type='html'>Suppose we know the month and year and we want to calculate the number of sunday in that month.&lt;br /&gt;&lt;br /&gt;Here is the code:&lt;br /&gt;&lt;blockquote&gt;private string GetNumberOfSundays(Int32 Month, Int32 Year)&lt;br /&gt;    {&lt;br /&gt;        DateTime StartDate = Convert.ToDateTime(Month.ToString() + "/01/" + Year.ToString());&lt;br /&gt;        Int32 iDays = DateTime.DaysInMonth(Year,Month);&lt;br /&gt;        DateTime EndDate = StartDate.AddDays(iDays - 1);&lt;br /&gt;        Int32 Count = 0;&lt;br /&gt;        Int32 SundayCount = 0;&lt;br /&gt;        while (StartDate.DayOfWeek != DayOfWeek.Sunday)&lt;br /&gt;        {&lt;br /&gt;            StartDate = StartDate.AddDays(1);&lt;br /&gt;        }&lt;br /&gt;        SundayCount = 1;&lt;br /&gt;        StartDate = StartDate.AddDays(7);&lt;br /&gt;        while (StartDate &lt;= EndDate)        {            SundayCount += 1;            StartDate = StartDate.AddDays(7);        }        return SundayCount.ToString();    }&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Pass the Month and Year as Integer value and the above method will return the number of sunday in that month as a string value.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8574296770627744703?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8574296770627744703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8574296770627744703&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8574296770627744703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8574296770627744703'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/12/code-to-find-number-of-sunday-for-given.html' title='Code To Find Number of Sunday for the given Month'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-3961820882645696028</id><published>2009-11-26T17:12:00.001+05:30</published><updated>2009-11-26T17:19:53.863+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Get IP Address of Client and Server Sytem</title><content type='html'>&lt;b&gt;Code To Get the IP Address of Host:&lt;/b&gt;&lt;br /&gt;&lt;blockquote&gt;private void GetHostaddress()&lt;br /&gt;{&lt;br /&gt;string strHostName = Dns.GetHostName();&lt;br /&gt;IPAddress[] ips;&lt;br /&gt;ips = Dns.GetHostAddresses(strHostName);&lt;br /&gt;foreach (IPAddress ip in ips)&lt;br /&gt;{&lt;br /&gt;Response.Write(ip);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;Code To Get the IP Address of Client's Machine:&lt;/b&gt;&lt;br /&gt;&lt;blockquote&gt;Request.UserHostAddress.ToString()&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-3961820882645696028?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/3961820882645696028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=3961820882645696028&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/3961820882645696028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/3961820882645696028'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/11/get-ip-address-of-client-and-server.html' title='Get IP Address of Client and Server Sytem'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-599852826138200754</id><published>2009-11-22T01:33:00.002+05:30</published><updated>2009-11-22T01:33:28.441+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Query to Get the dependencies for given Table Name</title><content type='html'>Following Query is used to get the dependencies for the given Table.&lt;br /&gt;Suppose we need to check the dependencies for the table tbl_Customer&lt;br /&gt;&lt;br /&gt;Sample Query:&lt;br /&gt;&lt;blockquote&gt;DECLARE @Objectname varchar(100)&lt;br /&gt;SET @Objectname='tbl_Customer'&lt;br /&gt;&lt;br /&gt;SELECT O1.name,O2.name FROM sys.sql_dependencies D INNER JOIN Sys.Objects O1 ON O1.object_id=D.object_id&lt;br /&gt;INNER JOIN Sys.Objects O2 ON O2.object_id=D.referenced_major_id&lt;br /&gt;WHERE O1.name=@Objectname OR O2.name=@Objectname&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-599852826138200754?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/599852826138200754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=599852826138200754&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/599852826138200754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/599852826138200754'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/11/query-to-get-dependencies-for-given.html' title='Query to Get the dependencies for given Table Name'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2157428837164344204</id><published>2009-11-22T01:32:00.005+05:30</published><updated>2009-11-22T01:32:55.786+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Query to get the name of the identity column for a given table</title><content type='html'>Query to get the name of the identity column for a given table.&lt;br /&gt;To Get the Identity column name for Tbl_Customer we need to execute the following query.&lt;br /&gt;&lt;blockquote&gt;SELECT D.name AS ColumnName, O.name AS TableName&lt;br /&gt;FROM sys.identity_columns D INNER JOIN Sys.Objects O ON O.object_id=D.object_id&lt;br /&gt;Where O.name='Tbl_Customer&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2157428837164344204?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2157428837164344204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2157428837164344204&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2157428837164344204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2157428837164344204'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/11/query-to-get-name-of-identity-column.html' title='Query to get the name of the identity column for a given table'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1341788339376234679</id><published>2009-11-22T01:32:00.002+05:30</published><updated>2009-11-22T01:32:25.944+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Query to Get the Forgien Key Name Their Primary Table and Referrence Table</title><content type='html'>Following Query will give you the List of Forgien Key in a Database with Their Primary and Referrence Tables Name.&lt;br /&gt;&lt;br /&gt;Sample Query:&lt;br /&gt;&lt;blockquote&gt;SELECT F.name AS ForgienKey,O2.name AS ParentTable,O3.name AS RefTable FROM sys.foreign_keys F&lt;br /&gt;INNER JOIN Sys.Objects O2 ON O2.object_id=F.parent_object_id&lt;br /&gt;INNER JOIN Sys.Objects O3 ON O3.object_id=F.referenced_object_id&lt;br /&gt;&lt;/blockquote&gt;If you want to get forgien key for a particular table then you can use like this:&lt;br /&gt;&lt;blockquote&gt;SELECT F.name AS ForgienKey,O2.name AS ParentTable,O3.name AS RefTable FROM sys.foreign_keys F&lt;br /&gt;INNER JOIN Sys.Objects O2 ON O2.object_id=F.parent_object_id&lt;br /&gt;INNER JOIN Sys.Objects O3 ON O3.object_id=F.referenced_object_id&lt;br /&gt;Where O3.name='Tbl_User'&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1341788339376234679?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1341788339376234679/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1341788339376234679&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1341788339376234679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1341788339376234679'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/11/query-to-get-forgien-key-name-their.html' title='Query to Get the Forgien Key Name Their Primary Table and Referrence Table'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1031973852231506733</id><published>2009-11-22T01:31:00.005+05:30</published><updated>2009-11-22T01:31:57.228+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>SQL Statement to Get the Definition of the Store Procedures</title><content type='html'>SQL Statement to Get the Definition of the System Store Procedures.&lt;br /&gt;&lt;blockquote&gt;SELECT definition FROM sys.system_sql_modules&lt;br /&gt;&lt;/blockquote&gt;SQL Statement to Get the Definition of the User defined Store Procedures.&lt;br /&gt;&lt;blockquote&gt;SELECT definition FROM sys.sql_modules&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1031973852231506733?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1031973852231506733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1031973852231506733&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1031973852231506733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1031973852231506733'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/11/sql-statement-to-get-definition-of.html' title='SQL Statement to Get the Definition of the Store Procedures'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2922716898110849465</id><published>2009-11-22T01:31:00.002+05:30</published><updated>2009-11-22T01:31:15.853+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Query in SQL Server to get the Parameter list of given Store Procedure</title><content type='html'>Write a Query in SQL Server to get the Parameter list of given Store Procedure.&lt;br /&gt;&lt;br /&gt;Suppose we want to get the name of the parameter for the Store Procedure&lt;br /&gt;Course_Insert_sp then folllowing needs to be executed.&lt;br /&gt;&lt;blockquote&gt;SELECT * FROM sys.parameters D INNER JOIN Sys.Objects O ON O.object_id=D.object_id WHERE O.name='Course_Insert_sp'&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2922716898110849465?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2922716898110849465/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2922716898110849465&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2922716898110849465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2922716898110849465'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/11/query-in-sql-server-to-get-parameter.html' title='Query in SQL Server to get the Parameter list of given Store Procedure'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2310759213812198021</id><published>2009-11-16T23:40:00.001+05:30</published><updated>2009-11-16T23:41:10.656+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Code to Get Twitter Follower's Count</title><content type='html'>When we send a request on  the following url http://twitter.com/statuses/user_timeline/lakhangarg.xml?count=1 then the XML data will be returned as a XML.&lt;br /&gt;&lt;br /&gt;This is sample XML retured from twitter:&lt;br /&gt;&lt;blockquote  style="color: #38761d;"&gt;&amp;lt;statuses type="array"&amp;gt;&lt;br /&gt;&amp;lt;status&amp;gt;&lt;br /&gt;&amp;lt;created_at&amp;gt;Tue Oct 27 16:44:10 +0000 2009&amp;lt;/created_at&amp;gt;&lt;br /&gt;&amp;lt;id&amp;gt;5204855334&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;lt;text&amp;gt;&lt;br /&gt;http://bit.ly/oUB92 Reading: Create Script File For Each Store Procedure And Save into Seperate SQL File For Each Store Procedure&lt;br /&gt;&amp;lt;/text&amp;gt;&lt;br /&gt;&amp;lt;source&amp;gt;web&amp;lt;/source&amp;gt;&lt;br /&gt;&amp;lt;truncated&amp;gt;false&amp;lt;/truncated&amp;gt;&lt;br /&gt;&amp;lt;in_reply_to_status_id/&amp;gt;&lt;br /&gt;&amp;lt;in_reply_to_user_id/&amp;gt;&lt;br /&gt;&amp;lt;favorited&amp;gt;false&amp;lt;/favorited&amp;gt;&lt;br /&gt;&amp;lt;in_reply_to_screen_name/&amp;gt;&lt;br /&gt;&amp;lt;user&amp;gt;&lt;br /&gt;&amp;lt;id&amp;gt;28538625&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;lt;name&amp;gt;Lakhan Pal Garg&amp;lt;/name&amp;gt;&lt;br /&gt;&amp;lt;screen_name&amp;gt;lakhangarg&amp;lt;/screen_name&amp;gt;&lt;br /&gt;&amp;lt;location/&amp;gt;&lt;br /&gt;&amp;lt;description/&amp;gt;&lt;br /&gt;&amp;lt;profile_image_url&amp;gt;&lt;br /&gt;http://a1.twimg.com/profile_images/319559736/PhotoFunia-19dab_normal.jpg&lt;br /&gt;&amp;lt;/profile_image_url&amp;gt;&lt;br /&gt;&amp;lt;url&amp;gt;http://lakhangarg.blogspot.com/&amp;lt;/url&amp;gt;&lt;br /&gt;&amp;lt;protected&amp;gt;false&amp;lt;/protected&amp;gt;&lt;br /&gt;&amp;lt;followers_count&amp;gt;16&amp;lt;/followers_count&amp;gt;&lt;br /&gt;&amp;lt;profile_background_color&amp;gt;9ae4e8&amp;lt;/profile_background_color&amp;gt;&lt;br /&gt;&amp;lt;profile_text_color&amp;gt;000000&amp;lt;/profile_text_color&amp;gt;&lt;br /&gt;&amp;lt;profile_link_color&amp;gt;0000ff&amp;lt;/profile_link_color&amp;gt;&lt;br /&gt;&amp;lt;profile_sidebar_fill_color&amp;gt;e0ff92&amp;lt;/profile_sidebar_fill_color&amp;gt;&lt;br /&gt;&amp;lt;profile_sidebar_border_color&amp;gt;87bc44&amp;lt;/profile_sidebar_border_color&amp;gt;&lt;br /&gt;&amp;lt;friends_count&amp;gt;15&amp;lt;/friends_count&amp;gt;&lt;br /&gt;&amp;lt;created_at&amp;gt;Fri Apr 03 10:39:09 +0000 2009&amp;lt;/created_at&amp;gt;&lt;br /&gt;&amp;lt;favourites_count&amp;gt;0&amp;lt;/favourites_count&amp;gt;&lt;br /&gt;&amp;lt;utc_offset&amp;gt;-36000&amp;lt;/utc_offset&amp;gt;&lt;br /&gt;&amp;lt;time_zone&amp;gt;Hawaii&amp;lt;/time_zone&amp;gt;&lt;br /&gt;&amp;lt;profile_background_image_url&amp;gt;&lt;br /&gt;http://s.twimg.com/a/1258070043/images/themes/theme1/bg.png&lt;br /&gt;&amp;lt;/profile_background_image_url&amp;gt;&lt;br /&gt;&amp;lt;profile_background_tile&amp;gt;false&amp;lt;/profile_background_tile&amp;gt;&lt;br /&gt;&amp;lt;statuses_count&amp;gt;12&amp;lt;/statuses_count&amp;gt;&lt;br /&gt;&amp;lt;notifications/&amp;gt;&lt;br /&gt;&amp;lt;geo_enabled&amp;gt;false&amp;lt;/geo_enabled&amp;gt;&lt;br /&gt;&amp;lt;verified&amp;gt;false&amp;lt;/verified&amp;gt;&lt;br /&gt;&amp;lt;following/&amp;gt;&lt;br /&gt;&amp;lt;/user&amp;gt;&lt;br /&gt;&amp;lt;geo/&amp;gt;&lt;br /&gt;&amp;lt;/status&amp;gt;&lt;br /&gt;&amp;lt;/statuses&amp;gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;b&gt;Sample code to get the follower count from the XML data is:&lt;/b&gt;&lt;br /&gt;&lt;blockquote  style="color: #38761d;"&gt;private static string GetTwitterFollowers(string TwitterURL)&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;if (TwitterURL != "")&lt;br /&gt;{&lt;br /&gt;TwitterURL = TwitterURL.Substring(TwitterURL.LastIndexOf('/') + 1);&lt;br /&gt;Uri uri = new Uri("http://twitter.com/statuses/user_timeline/" + TwitterURL + ".xml?count=1");&lt;br /&gt;HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);&lt;br /&gt;req.UserAgent = "Get Content";&lt;br /&gt;WebResponse resp = req.GetResponse();&lt;br /&gt;Stream stream = resp.GetResponseStream();&lt;br /&gt;StreamReader sr = new StreamReader(stream);&lt;br /&gt;string s = sr.ReadToEnd();&lt;br /&gt;System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();&lt;br /&gt;xDoc.LoadXml(s);&lt;br /&gt;string FollowerCount = xDoc.GetElementsByTagName("followers_count").Item(0).InnerText;&lt;br /&gt;if (FollowerCount == "")&lt;br /&gt;FollowerCount = "0";&lt;br /&gt;return FollowerCount;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;return "0";&lt;br /&gt;}&lt;br /&gt;catch&lt;br /&gt;{&lt;br /&gt;return "0";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2310759213812198021?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2310759213812198021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2310759213812198021&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2310759213812198021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2310759213812198021'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/11/code-to-get-twitter-followers-count.html' title='Code to Get Twitter Follower&apos;s Count'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-5584732401092624473</id><published>2009-10-27T22:04:00.001+05:30</published><updated>2009-10-27T22:05:37.420+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interview Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>SQL Server Interview Questions</title><content type='html'>&lt;b&gt;(1) How To Update Description Value for a Column in Table using SQL Command?&lt;/b&gt;&lt;br /&gt;We can Update Description to Column using sp_updateextendedproperty System Store Procedure.&lt;br /&gt;Sample Command to Update Description for Column in a Table:&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;EXEC sys.sp_updateextendedproperty @name=N'MS_Description', @value=N'My Description for Column Here' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTableName',&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @level2type=N'COLUMN',@level2name=N'ColumnName'&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;(2) How To Delete Description Value for a Column in Table using SQL Command?&lt;/b&gt;&lt;br /&gt;We can Delete Description from Column using sp_dropextendedproperty System Store Procedure.&lt;br /&gt;Sample Command to Delete Description from Column in a Table:&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;EXEC sys.sp_dropextendedproperty @name=N'MS_Description', @value=N'My Description for Column Here' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTableName',&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @level2type=N'COLUMN',@level2name=N'ColumnName'&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;(3) How we can add Description to the Column using Sql Command?&lt;/b&gt;&lt;br /&gt;We can Add Description to Column using sp_addextendedproperty System Store Procedure.&lt;br /&gt;Sample Command to Insert Description for Column in a Table:&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'My Description for Column Here' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTableName',&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @level2type=N'COLUMN',@level2name=N'ColumnName'&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;(4) How To Get Description Value for all Column in Table using SQL Command?&lt;/b&gt;&lt;br /&gt;To Get Description of Columns we need to use system function sys.fn_listextendedproperty.&lt;br /&gt;Command To Get Description Data for all Columns:&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;SELECT * FROM&amp;nbsp;&amp;nbsp; fn_listextendedproperty(NULL, 'SCHEMA',&lt;br /&gt;&amp;nbsp;'dbo', 'TABLE', 'YourTable Name Here', 'COLUMN', NULL)&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;(5) How To Get Description Value for Single Column in Table using SQL Command?&lt;/b&gt;&lt;br /&gt;To Get Description of Single Column we need to use system function sys.fn_listextendedproperty. we need to pass the column Name is this case.&lt;br /&gt;Command To Get Description Data for Single Columns:&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;SELECT * FROM&amp;nbsp;&amp;nbsp; fn_listextendedproperty(NULL, 'SCHEMA',&lt;br /&gt;&amp;nbsp;'dbo', 'TABLE', 'Table Name Here', 'COLUMN', 'Column Name Here')&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;(6) How We can get the DB name using SQL Command?&lt;/b&gt;&lt;br /&gt;Following is the Command to get the DB name using Command analyzer&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;SELECT DB_NAME()&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;(7) What is the use of Set NOCOUNT ON;?&lt;/b&gt;&lt;br /&gt;By Default When we execute any command it return us the number of record affected. if we don't want to return the number of records affected then we can use &lt;br /&gt;&lt;div style="color: #38761d;"&gt;SET NOCOUNT ON;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-5584732401092624473?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/5584732401092624473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=5584732401092624473&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5584732401092624473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5584732401092624473'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/10/sql-server-interview-questions.html' title='SQL Server Interview Questions'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8215021615415041594</id><published>2009-10-27T21:47:00.002+05:30</published><updated>2009-10-27T21:50:20.375+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Store Procedure To Create Script for Create Table</title><content type='html'>Following is the store procedure to create script for create table. this will create script for all constraint, description of columns, and index etc.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Store Procedure Script:&lt;/b&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;div style="color: #38761d;"&gt;ALTER PROCEDURE sp_CreateTableScript      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;@TableName SYSNAME,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;@IncludeConstraints BIT = 1,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;@IncludeIndexes BIT = 1,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;@NewTableName SYSNAME = NULL,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;@UseSystemDataTypes BIT = 0      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;AS      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;BEGIN     &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SET NOCOUNT ON;    &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @MainDefinition TABLE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldValue NVARCHAR(500)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @DBName SYSNAME      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @ClusteredPK BIT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @TableSchema NVARCHAR(255)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SET @DBName = DB_NAME(DB_ID())      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT @TableName = name FROM sysobjects WHERE id = OBJECT_ID(@TableName)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @ShowFields TABLE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldID INT IDENTITY(1,1),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DatabaseName VARCHAR(100),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;TableOwner VARCHAR(100),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;TableName VARCHAR(100),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldName VARCHAR(100),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ColumnPosition INT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ColumnDefaultValue VARCHAR(100),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ColumnDefaultName VARCHAR(100),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IsNullable BIT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DataType VARCHAR(100),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;MaxLength INT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;NumericPrecision INT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;NumericScale INT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DomainName VARCHAR(100),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldListingName VARCHAR(110),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldDefinition CHAR(1),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IdentityColumn BIT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IdentitySeed INT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IdentityIncrement INT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IsCharColumn BIT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @HoldingArea TABLE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FldID SMALLINT IDENTITY(1,1),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;Flds VARCHAR(4000),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FldValue CHAR(1) DEFAULT(0)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @PKObjectID TABLE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ObjectID INT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @Uniques TABLE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ObjectID INT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @HoldingAreaValues TABLE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FldID SMALLINT IDENTITY(1,1),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;Flds VARCHAR(4000),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FldValue CHAR(1) DEFAULT(0)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DECLARE @Definition TABLE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DefinitionID SMALLINT IDENTITY(1,1),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldValue NVARCHAR(500)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @ShowFields      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(             &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DatabaseName,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;TableOwner,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;TableName,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldName,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ColumnPosition,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ColumnDefaultValue,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ColumnDefaultName,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IsNullable,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DataType,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;MaxLength,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;NumericPrecision,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;NumericScale,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DomainName,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldListingName,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FieldDefinition,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IdentityColumn,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IdentitySeed,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IdentityIncrement,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IsCharColumn      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DB_NAME(),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;TABLE_SCHEMA,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;TABLE_NAME,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;COLUMN_NAME,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CAST(ORDINAL_POSITION AS INT),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;COLUMN_DEFAULT,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;dobj.name AS ColumnDefaultName,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE WHEN c.IS_NULLABLE = 'YES' THEN 1 ELSE 0 END,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DATA_TYPE,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CAST(CHARACTER_MAXIMUM_LENGTH AS INT),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CAST(NUMERIC_PRECISION AS INT),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CAST(NUMERIC_SCALE AS INT),      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DOMAIN_NAME,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;COLUMN_NAME + ',','' AS FieldDefinition,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE WHEN ic.object_id IS NULL THEN 0 ELSE 1 END AS IdentityColumn,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CAST(ISNULL(ic.seed_value,0) AS INT) AS IdentitySeed,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CAST(ISNULL(ic.increment_value,0) AS INT) AS IdentityIncrement,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE WHEN st.collation_name IS NOT NULL THEN 1 ELSE 0 END AS IsCharColumn      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INFORMATION_SCHEMA.COLUMNS c      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.columns sc ON  c.TABLE_NAME = OBJECT_NAME(sc.object_id) AND c.COLUMN_NAME = sc.Name      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;LEFT JOIN sys.identity_columns ic ON c.TABLE_NAME = OBJECT_NAME(ic.object_id) AND c.COLUMN_NAME = ic.Name      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.types st ON COALESCE(c.DOMAIN_NAME,c.DATA_TYPE) = st.name      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;LEFT OUTER JOIN sys.objects dobj ON dobj.object_id = sc.default_object_id AND dobj.type = 'D'      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE c.TABLE_NAME = @TableName      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ORDER BY      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;c.TABLE_NAME, c.ORDINAL_POSITION      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT TOP 1 @TableSchema = TableOwner      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM @ShowFields      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @HoldingArea (Flds) VALUES('(')      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;VALUES('CREATE TABLE ' + CASE WHEN @NewTableName IS NOT NULL THEN @NewTableName ELSE @TableSchema + '.' + @TableName END)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;VALUES('(')      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CHAR(10) + FieldName + ' ' +      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHEN DomainName IS NOT NULL AND @UseSystemDataTypes = 0 THEN     &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;DomainName + CASE WHEN IsNullable = 1 THEN ' NULL ' ELSE ' NOT NULL ' END      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ELSE UPPER(DataType) +      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE WHEN IsCharColumn = 1 THEN '(' + CAST(MaxLength AS VARCHAR(10)) + ')' ELSE '' END +      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE WHEN IdentityColumn = 1 THEN     &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;' IDENTITY(' + CAST(IdentitySeed AS VARCHAR(5))+ ',' + CAST(IdentityIncrement AS VARCHAR(5)) + ')' ELSE '' END +      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE WHEN IsNullable = 1 THEN ' NULL ' ELSE ' NOT NULL ' END +      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE WHEN ColumnDefaultName IS NOT NULL AND @IncludeConstraints = 1 THEN    &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;'CONSTRAINT [' + ColumnDefaultName + '] DEFAULT' + UPPER(ColumnDefaultValue) ELSE '' END      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;END +       &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;CASE WHEN FieldID = (SELECT MAX(FieldID) FROM @ShowFields) THEN '' ELSE ',' END      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM    @ShowFields       &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IF @IncludeConstraints = 1      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;BEGIN      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;',CONSTRAINT [' + name + '] FOREIGN KEY (' + ParentColumns + ') REFERENCES [' + ReferencedObject + '](' + ReferencedColumns + ')'      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;(      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ReferencedObject = OBJECT_NAME(fk.referenced_object_id), ParentObject = OBJECT_NAME(parent_object_id),fk.name,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;REVERSE(SUBSTRING(REVERSE((      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT cp.name + ','      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sys.foreign_key_columns fkc      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.columns cp ON fkc.parent_object_id = cp.object_id AND fkc.parent_column_id = cp.column_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE fkc.constraint_object_id = fk.object_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FOR XML PATH('')      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)), 2, 8000)) ParentColumns,      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;REVERSE(SUBSTRING(REVERSE((      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT cr.name + ','      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sys.foreign_key_columns fkc      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.columns cr ON fkc.referenced_object_id = cr.object_id AND fkc.referenced_column_id = cr.column_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE fkc.constraint_object_id = fk.object_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FOR XML PATH('')      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)), 2, 8000)) ReferencedColumns      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM sys.foreign_keys fk      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;) a      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE ParentObject = @TableName      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT',CONSTRAINT [' + name + '] CHECK ' + definition FROM sys.check_constraints      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE OBJECT_NAME(parent_object_id) = @TableName      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @PKObjectID(ObjectID)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT DISTINCT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;PKObject = cco.object_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sys.key_constraints cco      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.index_columns cc ON cco.parent_object_id = cc.object_id AND cco.unique_index_id = cc.index_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.indexes i ON cc.object_id = i.object_id AND cc.index_id = i.index_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;OBJECT_NAME(parent_object_id) = @TableName    AND         &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;i.type = 1 AND      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;is_primary_key = 1      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Uniques(ObjectID)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT DISTINCT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;PKObject = cco.object_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sys.key_constraints cco      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.index_columns cc ON cco.parent_object_id = cc.object_id AND cco.unique_index_id = cc.index_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.indexes i ON cc.object_id = i.object_id AND cc.index_id = i.index_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;OBJECT_NAME(parent_object_id) = @TableName AND             &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;i.type = 2 AND      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;is_primary_key = 0 AND      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;is_unique_constraint = 1       &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SET @ClusteredPK = CASE WHEN @@ROWCOUNT &amp;gt; 0 THEN 1 ELSE 0 END      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT    ',CONSTRAINT ' + name + CASE type WHEN 'PK' THEN     &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;' PRIMARY KEY ' + CASE WHEN pk.ObjectID IS NULL THEN ' NONCLUSTERED ' ELSE ' CLUSTERED ' END      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHEN 'UQ' THEN ' UNIQUE ' END + CASE WHEN u.ObjectID IS NOT NULL THEN ' NONCLUSTERED ' ELSE '' END + '(' +      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;REVERSE(SUBSTRING(REVERSE((      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;c.name +  + CASE WHEN cc.is_descending_key = 1 THEN ' DESC' ELSE ' ASC' END + ','      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sys.key_constraints ccok      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;LEFT JOIN sys.index_columns cc ON ccok.parent_object_id = cc.object_id AND cco.unique_index_id = cc.index_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;LEFT JOIN sys.columns c ON cc.object_id = c.object_id AND cc.column_id = c.column_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;LEFT JOIN sys.indexes i ON cc.object_id = i.object_id AND cc.index_id = i.index_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;i.object_id = ccok.parent_object_id AND      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ccok.object_id = cco.object_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FOR XML PATH('')      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)), 2, 8000)) + ')'      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sys.key_constraints cco      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;LEFT JOIN @PKObjectID pk ON cco.object_id = pk.ObjectID      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;LEFT JOIN @Uniques u ON cco.object_id = u.objectID      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;OBJECT_NAME(cco.parent_object_id) = @TableName      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;END      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;VALUES(')')  &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;VALUES('GO')    &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;IF @IncludeIndexes = 1      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;BEGIN      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ISNULL(('CREATE ' + type_desc + ' INDEX [' + [name] COLLATE SQL_Latin1_General_CP1_CI_AS + '] ON [' +  OBJECT_NAME(object_id) + '] (' +      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;REVERSE(SUBSTRING(REVERSE((      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT name + CASE WHEN sc.is_descending_key = 1 THEN ' DESC' ELSE ' ASC' END + ','      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sys.index_columns sc      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;JOIN sys.columns c ON sc.object_id = c.object_id AND sc.column_id = c.column_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;OBJECT_NAME(sc.object_id) = @TableName AND      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sc.object_id = i.object_id AND      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;sc.index_id = i.index_id      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ORDER BY index_column_id ASC      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FOR XML PATH('')      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;)), 2, 8000)) + ')'  ),'')    &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM sys.indexes i      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;WHERE      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;OBJECT_NAME(object_id) = @TableName      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;AND CASE WHEN @ClusteredPK = 1 AND is_primary_key = 1 AND type = 1 THEN 0 ELSE 1 END = 1      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;AND is_unique_constraint = 0      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;AND is_primary_key = 0      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;END   &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @Definition(FieldValue)     &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT   'EXEC sys.sp_addextendedproperty @name=N'''+name+''', @value=N'''+CONVERT(varchar(100),value)+''' , @level0type=N''SCHEMA'',@level0name=N''dbo'', @level1type=N''TABLE'',@level1name=N'''+@TableName+''', &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;@level2type=N''COLUMN'',@level2name=N'''+objName+''''&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;FROM   ::fn_listextendedproperty(NULL, 'SCHEMA',&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;'dbo', 'TABLE', @TableName, 'COLUMN', NULL) WHERE CONVERT(varchar(100),value)&amp;lt;&amp;gt;''  &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;INSERT INTO @MainDefinition(FieldValue)      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT FieldValue FROM @Definition      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;ORDER BY DefinitionID ASC      &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #38761d;"&gt;SELECT * FROM @MainDefinition      &lt;br /&gt;&lt;/div&gt;&lt;span style="color: #38761d;"&gt;END&lt;/span&gt; &lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;How to execute the above store procedure and get the create table script:&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;EXEC sp_CreateTableScript 'TableName'&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8215021615415041594?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8215021615415041594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8215021615415041594&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8215021615415041594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8215021615415041594'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/10/store-procedure-to-create-script-for.html' title='Store Procedure To Create Script for Create Table'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8146396596146165865</id><published>2009-10-27T21:34:00.001+05:30</published><updated>2009-10-27T21:36:24.441+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Create Script File For Each Store Procedure And Save into Seperate SQL File For Each</title><content type='html'>With the help of &lt;b&gt;sqlcmd utility&lt;/b&gt; we can save the script of store procedure in separate file for each store procedure.&lt;br /&gt;&lt;br /&gt;Name of the file will be same as the name of the store procedure.&lt;br /&gt;&lt;b&gt;Sample Code to Create Script and Save&lt;/b&gt;:&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;select N'sqlcmd -U sa -P sa -S localhost -d DataBaseName -Q "exec sp_helptext ' + name + N' " -h-1 -k 1 &amp;gt;&amp;gt; c:\DB\sp\' + name + N'.sql' from sys.objects where type='P'&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;When you will execute the above command the following output will be generated based on the number of store procedure in your database:&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: #38761d;"&gt;sqlcmd -U sa -P sa -S localhost -d DataBaseName -Q "exec sp_helptext User_Authenticate_sp " -h-1 -k 1 &amp;gt;&amp;gt; c:\DB\sp\User_Authenticate_sp.sql&lt;br /&gt;sqlcmd -U sa -P sa -S localhost -d DataBaseName -Q "exec sp_helptext User_GetPassword_sp " -h-1 -k 1 &amp;gt;&amp;gt; c:\DB\sp\User_GetPassword_sp.sql&lt;br /&gt;sqlcmd -U sa -P sa -S localhost -d DataBaseName -Q "exec sp_helptext sp_upgraddiagrams " -h-1 -k 1 &amp;gt;&amp;gt; c:\DB\sp\sp_upgraddiagrams.sql&lt;br /&gt;sqlcmd -U sa -P sa -S localhost -d DataBaseName -Q "exec sp_helptext sp_helpdiagrams " -h-1 -k 1 &amp;gt;&amp;gt; c:\DB\sp\sp_helpdiagrams.sql&lt;br /&gt;sqlcmd -U sa -P sa -S localhost -d DataBaseName -Q "exec sp_helptext sp_helpdiagramdefinition " -h-1 -k 1 &amp;gt;&amp;gt; c:\DB\sp\sp_helpdiagramdefinition.sql&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Save these output data into a batch file execute this batch file. this will save the store procedure script on &lt;b&gt;C:\DB\sp&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8146396596146165865?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8146396596146165865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8146396596146165865&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8146396596146165865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8146396596146165865'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/10/create-script-file-for-each-store.html' title='Create Script File For Each Store Procedure And Save into Seperate SQL File For Each'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1269361527344014057</id><published>2009-10-06T15:10:00.002+05:30</published><updated>2009-10-06T15:18:54.555+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Decrypt String Data</title><content type='html'>To decrypt data we need to pass the encrypted string data.&lt;br /&gt;To see the code to Encrypt string data &lt;a href="http://lakhangarg.blogspot.com/2009/10/encrypt-string-data.html"&gt;click here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: #6aa84f;"&gt;public static string Decrypt(string cipherString)&lt;br /&gt;{&lt;br /&gt;byte[] keyArray;&lt;br /&gt;//get the byte code of the string&lt;br /&gt;byte[] toEncryptArray = Convert.FromBase64String(cipherString);&lt;br /&gt;string key = ")(*&amp;amp;";&lt;br /&gt;//if hashing was used get the hash code with regards to your key&lt;br /&gt;MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();&lt;br /&gt;keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));&lt;br /&gt;//release any resource held by the MD5CryptoServiceProvider&lt;br /&gt;hashmd5.Clear();&lt;br /&gt;&lt;br /&gt;TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();&lt;br /&gt;//set the secret key for the tripleDES algorithm&lt;br /&gt;tdes.Key = keyArray;&lt;br /&gt;//mode of operation. there are other 4 modes. We choose ECB(Electronic code Book)&lt;br /&gt;&lt;br /&gt;tdes.Mode = CipherMode.ECB;&lt;br /&gt;//padding mode(if any extra byte added)&lt;br /&gt;tdes.Padding = PaddingMode.PKCS7;&lt;br /&gt;&lt;br /&gt;ICryptoTransform cTransform = tdes.CreateDecryptor();&lt;br /&gt;byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);&lt;br /&gt;//Release resources held by TripleDes Encryptor                &lt;br /&gt;tdes.Clear();&lt;br /&gt;//return the Clear decrypted TEXT&lt;br /&gt;return UTF8Encoding.UTF8.GetString(resultArray);&lt;br /&gt;} &lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1269361527344014057?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1269361527344014057/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1269361527344014057&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1269361527344014057'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1269361527344014057'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/10/decrypt-string-data.html' title='Decrypt String Data'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-5709581202498744741</id><published>2009-10-06T15:01:00.005+05:30</published><updated>2009-10-06T15:18:21.629+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Encrypt a string Data</title><content type='html'>Pass the string data to this function and this function will return the encrypted string. To see the code to decrypt string data &lt;a href="http://lakhangarg.blogspot.com/2009/10/decrypt-string-data.html"&gt;click here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: #6aa84f;"&gt;public static string Encrypt(string toEncrypt)&lt;br /&gt;{&lt;br /&gt;byte[] keyArray;&lt;br /&gt;byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);&lt;br /&gt;string key = ")(*&amp;amp;";&lt;br /&gt;MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();&lt;br /&gt;keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));&lt;br /&gt;//Always release the resources and flush data of the Cryptographic service provide. Best Practice&lt;br /&gt;hashmd5.Clear();&lt;br /&gt;TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();&lt;br /&gt;//set the secret key for the tripleDES algorithm&lt;br /&gt;tdes.Key = keyArray;&lt;br /&gt;//mode of operation. there are other 4 modes. We choose ECB(Electronic code Book)&lt;br /&gt;tdes.Mode = CipherMode.ECB;&lt;br /&gt;//padding mode(if any extra byte added)&lt;br /&gt;&lt;br /&gt;tdes.Padding = PaddingMode.PKCS7;&lt;br /&gt;&lt;br /&gt;ICryptoTransform cTransform = tdes.CreateEncryptor();&lt;br /&gt;//transform the specified region of bytes array to resultArray&lt;br /&gt;byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);&lt;br /&gt;//Release resources held by TripleDes Encryptor&lt;br /&gt;tdes.Clear();&lt;br /&gt;//Return the encrypted data into unreadable string format&lt;br /&gt;return Convert.ToBase64String(resultArray, 0, resultArray.Length);&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-5709581202498744741?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/5709581202498744741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=5709581202498744741&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5709581202498744741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5709581202498744741'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/10/encrypt-string-data.html' title='Encrypt a string Data'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1813552184554861128</id><published>2009-09-29T16:00:00.006+05:30</published><updated>2009-09-29T16:07:15.160+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Method to Get Time Elapsed With Refernce to Current Date Time</title><content type='html'>With the help of following code we can get the time elapsed with refernce to current date time.&lt;br /&gt;&lt;br /&gt;Pass the Previous Activities Date Time and the following function will return time elapsed in the format:&lt;br /&gt;&lt;b&gt;{Number} hour/hours ago,{Number} Day/Days ago,{Number} week/weeks ago,{Number} month/months ago&lt;/b&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: #6aa84f;"&gt;public static string GetDaysAgo(string strCreatedDateTime)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;DateTime CreatedDateTime = Convert.ToDateTime(strCreatedDateTime);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;string StrReturn = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;TimeSpan TimeDiff = DateTime.Now - CreatedDateTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;double MinDiff = Convert.ToDouble(TimeDiff.TotalMinutes.ToString());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;if (MinDiff &amp;lt; 0)                     MinDiff = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;if (MinDiff &amp;lt; 60)                     StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " minutes ago";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;else                 {                     MinDiff = MinDiff / 60; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;if (MinDiff &amp;lt; 24)                         if (Math.Floor(Convert.ToDecimal(MinDiff)) == 1)                             StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " hour ago"; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;else                             StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " hours ago"; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;else                     {                         MinDiff = MinDiff / 24;   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;if (MinDiff &amp;lt; 7)                             if (Math.Floor(Convert.ToDecimal(MinDiff)) == 1)                                 StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " day ago";  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;else                                 StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " days ago";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;else if (MinDiff &amp;lt; 30)                         {                             MinDiff = MinDiff / 7;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;if (Math.Floor(Convert.ToDecimal(MinDiff)) == 1)                                 StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " week ago";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;else                                 StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " weeks ago";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;}                         else                         {                             MinDiff = MinDiff / 30; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;if (Math.Floor(Convert.ToDecimal(MinDiff)) == 1)                                 StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " month ago";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;else                                 StrReturn = Math.Floor(Convert.ToDecimal(MinDiff)).ToString() + " months ago";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;}                     }                 }                 return StrReturn;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;}             catch (Exception ex)             {                 return "1 months ago";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;}         }&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;Call this function like this:&lt;br /&gt;&lt;blockquote&gt;GetDaysAgo("30/8/2009");&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1813552184554861128?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1813552184554861128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1813552184554861128&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1813552184554861128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1813552184554861128'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/method-to-get-time-elapsed-with.html' title='Method to Get Time Elapsed With Refernce to Current Date Time'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-7672439392966030912</id><published>2009-09-26T12:03:00.001+05:30</published><updated>2009-09-26T12:03:32.226+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Store Procedure to be Used in Custom Pagging</title><content type='html'>With the help of the below set of query we can get the number of record that we want to show to user.&lt;br /&gt;&lt;br /&gt;For this we need to pass two parameters. first is the @RecordsToPick (Number of Records that you want to picjk for the page)   and the second is @PageNumber (Page number for which you want to get the records from Database.)&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;USE DBName&lt;br /&gt;GO&lt;br /&gt;DECLARE @RecordsToPick smallint, @PageNumber smallint&lt;br /&gt;SET @RecordsToPick = 10&lt;br /&gt;SET @PageNumber = 2&lt;br /&gt;&lt;br /&gt;DECLARE @StartRow INT&lt;br /&gt;DECLARE @EndRow INT&lt;br /&gt;SET @StartRow = ((@PageNumber-1) * @RecordsToPick)&lt;br /&gt;SET @EndRow = @StartRow + @RecordsToPick&lt;br /&gt;&lt;br /&gt;SELECT * FROM ( SELECT UserName,UserID,City,State,Country ROW_NUMBER()OVER(ORDER BY UserID) AS RowNumber&lt;br /&gt;FROM as_TblMembers) As AliasName WHERE RowNumber &gt; @StartRow AND RowNumber &lt;= @EndRowGO&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;In the above store procedure first we will get the @StartRow  and @EndRow  to get the number of first record and last record respectively.&lt;br /&gt;&lt;blockquote&gt;ROW_NUMBER()OVER(ORDER BY UserID) AS RowNumber&lt;br /&gt;&lt;/blockquote&gt;ROW_NUMBER() will assign a unique number to each query order by UserID. with the help of it is easy for us to get the required result.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-7672439392966030912?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/7672439392966030912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=7672439392966030912&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7672439392966030912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7672439392966030912'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/store-procedure-to-be-used-in-custom.html' title='Store Procedure to be Used in Custom Pagging'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2331158606957005407</id><published>2009-09-22T14:59:00.003+05:30</published><updated>2009-09-22T15:03:48.821+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Discussion'/><title type='text'>Post Your Queries</title><content type='html'>Hello Friends,&lt;br /&gt;&lt;br /&gt;You can post your queries here in this section as a comment. I will try my best to answer those queries or you can also post answer to the queries posted by other people. In this way you can help other and get help from others.&lt;br /&gt;&lt;br /&gt;Thanks &amp;amp; Regards&lt;br /&gt;Lakhan Pal Garg&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2331158606957005407?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2331158606957005407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2331158606957005407&amp;isPopup=true' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2331158606957005407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2331158606957005407'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/post-your-queries.html' title='Post Your Queries'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6330408521761072072</id><published>2009-09-18T10:35:00.004+05:30</published><updated>2009-09-24T10:42:21.829+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Validate Textbox Value for Special Character Paste Data</title><content type='html'>&lt;a href="http://lakhangarg.blogspot.com/search/label/JavaScript"&gt;JavaScript&lt;/a&gt; Method to Validate '&amp;lt;' and '&amp;gt;' Character on paste data in text box or in Text Area.&lt;br /&gt;Read the Text from clipboard and validate using ValidateText Function.&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: #009900;"&gt;function OnTextPaste()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;{    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    var data="";    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    data=window.clipboardData.getData("Text");                    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    if(data)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        var ret=ValidateText(data);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        if(!ret)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;            alert('Sorry, you can not paste text having &amp;lt;, &amp;gt; in it.');&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        return ret;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        return false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;function ValidateText(str)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    var ret;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    if(str.indexOf('&amp;lt;') != -1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        ret=false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    else if(str.indexOf('&amp;gt;') != -1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        ret=false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        ret=true;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    return ret;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6330408521761072072?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6330408521761072072/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6330408521761072072&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6330408521761072072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6330408521761072072'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/validate-textbox-value-for-special.html' title='Validate Textbox Value for Special Character Paste Data'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2045630752101279668</id><published>2009-09-17T11:56:00.005+05:30</published><updated>2009-09-24T10:47:49.666+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Create XML Data From SQL Server Using "For XML Explicit"</title><content type='html'>There are different ways to get data in &lt;a href="http://lakhangarg.blogspot.com/search/label/XML"&gt;XML&lt;/a&gt; format from&lt;a href="http://lakhangarg.blogspot.com/search/label/SQL%20Server"&gt; SQL Server&lt;/a&gt; like:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;For XML Auto&lt;/li&gt;&lt;li&gt;For XML RAW&lt;/li&gt;&lt;li&gt;For XML Explicit&lt;/li&gt;&lt;/ul&gt;But in the first and second method we can't customize the format of &lt;a href="http://lakhangarg.blogspot.com/search/label/XML"&gt;XML&lt;/a&gt;. if we need customize XML then we need to use "For XML Explicit Method" With the Help of "For &lt;a href="http://lakhangarg.blogspot.com/search/label/XML"&gt;XML&lt;/a&gt; Explicit" we can create XML in the required format.&lt;br /&gt;&lt;br /&gt;'Tag' and 'Parent' Column are used to determine the hierarchy of xml.&lt;br /&gt;Now this code will generate a parent node name root and Session as Child of Root.&lt;br /&gt;&lt;br /&gt;[Session!2!ID] this will create an attribute of Session Node Named ID.&lt;br /&gt;and [Session!2!Notes!element] this will create a Child element of Session Named Notes.&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;Sample Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;SELECT    1    AS Tag, &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    NULL    AS Parent,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    NULL    AS [Session!2!ID],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    NULL    AS [Session!2!Notes!element],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    0    AS [root!1!Customer!hide]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;UNION ALL&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;SELECT    2            AS Tag, &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    1            AS Parent,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    Session.SessionID    AS [Session!2!ID],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    Session.Notes    AS [Session!2!Notes!element],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    1            AS [root!1!Customer!hide]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;FROM tbl_Session AS Session WHERE Session.SessionID&amp;lt;20&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;FOR XML EXPLICIT&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2045630752101279668?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2045630752101279668/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2045630752101279668&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2045630752101279668'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2045630752101279668'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/create-xml-data-from-sql-server-using.html' title='Create XML Data From SQL Server Using &quot;For XML Explicit&quot;'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8537712499266491796</id><published>2009-09-16T18:06:00.004+05:30</published><updated>2009-09-24T10:48:15.289+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Hide JavaScript Error</title><content type='html'>This Method is used to Handle &lt;a href="http://lakhangarg.blogspot.com/search/label/JavaScript"&gt;JavaScript&lt;/a&gt; Error that we don't want to show in case of unavoidable conditions.&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;function handleError()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;window.onerror =  handleError;&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8537712499266491796?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8537712499266491796/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8537712499266491796&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8537712499266491796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8537712499266491796'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/hide-javascript-error.html' title='Hide JavaScript Error'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2194371448077100087</id><published>2009-09-15T14:04:00.004+05:30</published><updated>2009-09-24T10:49:16.536+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Parse XML Data in SQL Server 2005 without using OPENXML Method</title><content type='html'>In &lt;a href="http://lakhangarg.blogspot.com/search/label/SQL%20Server"&gt;SQL Server 2005&lt;/a&gt; we can parse the XML Data without using OPENXML Methods that was used in SQL Server 2000.&lt;br /&gt;&lt;br /&gt;There are few methods defined in &lt;a href="http://lakhangarg.blogspot.com/search/label/SQL%20Server"&gt;SQL Server 2005&lt;/a&gt; for XML DataType like:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;nodes&lt;/li&gt;&lt;li&gt;query&lt;/li&gt;&lt;li&gt;value&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Sample Code:&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: #009900;"&gt;DECLARE @XmlData xml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;SET @XmlData='&amp;lt;Library&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    &amp;lt;Subject name="ASP.NET"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      &amp;lt;Book ID="1"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Author&amp;gt;Lakhan Pal Garg&amp;lt;/Author&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Title&amp;gt;ASP.NET Tips&amp;lt;/Title&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Price&amp;gt;$100&amp;lt;/Price&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      &amp;lt;/Book&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      &amp;lt;Book ID="2"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Author&amp;gt;Lakhan Pal Garg&amp;lt;/Author&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Title&amp;gt;SQL Server Tips&amp;lt;/Title&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Price&amp;gt;$90&amp;lt;/Price&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      &amp;lt;/Book&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    &amp;lt;/Subject&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    &amp;lt;Subject name="XML"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      &amp;lt;Book ID="3"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Author&amp;gt;Peter&amp;lt;/Author&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Title&amp;gt;XSLT Tutorial&amp;lt;/Title&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Price&amp;gt;$140&amp;lt;/Price&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      &amp;lt;/Book&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      &amp;lt;Book ID="4"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Author&amp;gt;Rihana&amp;lt;/Author&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Title&amp;gt;XML Parsing in SQL Server&amp;lt;/Title&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;        &amp;lt;Price&amp;gt;$120&amp;lt;/Price&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      &amp;lt;/Book&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    &amp;lt;/Subject&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;  &amp;lt;/Library&amp;gt;'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;select R.i.value('@ID', 'varchar(30)')   [BookID],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;       R.i.query('Author').value('.', 'varchar(30)')   [Author],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;       R.i.query('Title').value('.', 'varchar(30)')   [Title],&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;       R.i.query('Price').value('.', 'varchar(30)')   [Price]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;from  @XmlData.nodes('/Library/Subject/Book') R(i)&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;In the above Select Statement we have used &lt;span style="color: black;"&gt;@XmlData.nodes and this will return a node list we used the Alias for this "R" and i is the &lt;/span&gt;index of the node. now to read the value of a attribute we can use R.i.value('@ID','INT') [BookID] here BookID is Alias name for column. and to read the value of an element that is child of Book we need to write like this R.i.query('Author').value('.','varchar(30)') [AuthorName] Author is the name of Child element of Book.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2194371448077100087?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2194371448077100087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2194371448077100087&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2194371448077100087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2194371448077100087'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/parse-xml-data-in-sql-server-2005.html' title='Parse XML Data in SQL Server 2005 without using OPENXML Method'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6546459529920109127</id><published>2009-09-14T13:16:00.005+05:30</published><updated>2009-09-24T10:51:59.998+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Payment Gateway'/><title type='text'>Payment Gateway Integration - Plimus</title><content type='html'>To integrate Plimus first we need to create an account. using our account we can create products and contract in the products. we can define number of contract in a single product.&lt;br /&gt;&lt;br /&gt;You can define products and contract either of recurring type or of non-recurring type too.&lt;br /&gt;&lt;br /&gt;Here is a Sample code to integrate plimus as payment gateway either for one time payment or for Recurring payment.&lt;br /&gt;&lt;blockquote&gt;&amp;lt;form id="form1" action="https://sandbox.plimus.com/jsp/buynow.jsp" method="post"&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="contractId" value="2114108" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="quantity" value="1" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="overridePrice" value="20" /&amp;gt; &lt;br /&gt;&amp;lt;input type="hidden" name="custom1" value="1001" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="enableCustom" value="Y" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="firstName" value="Lakhan" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="lastName" value="Pal" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="email" value="lakhangarg@gmail.com" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="address1" value="6252 NW 65 Terrace" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="address2" value="Test Course" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="city" value="Parkland" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="zipCode" value="33067" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="country" value="us" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="state" value="FL" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="workPhone" value="1-858-350-7473" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="cardNumber" value="4111111111111111" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="verifyCardCode" value="411" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="bCur" value="USD" /&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="currency" value="USD" /&amp;gt;&lt;br /&gt;&amp;lt;input type="submit" id="btnSubmit" name="btnSubmit" value="Plimus - Pay Now"/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;/blockquote&gt;in the above sample &lt;span style="font-weight: bold;"&gt;custom1&lt;/span&gt; defined as the custom variable we can define maximum five custom variable from the plimus site for each contract. on the contract detail page there is a link custom field to define custom variables.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;bCur&lt;/span&gt; is used for base currency and &lt;span style="font-weight: bold;"&gt;currency &lt;/span&gt;is used to convert base currency into required type&lt;span style="font-weight: bold;"&gt;.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6546459529920109127?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6546459529920109127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6546459529920109127&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6546459529920109127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6546459529920109127'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/payment-gateway-integrate-plimus.html' title='Payment Gateway Integration - Plimus'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-4935352815477431239</id><published>2009-09-11T16:51:00.003+05:30</published><updated>2009-09-24T10:53:48.858+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>C# Connectivity with MYSQL using ODBC</title><content type='html'>First of all Downlaod &lt;a href="ftp://ftp.kreonet.re.kr/tools/db/mysql/Downloads/MyODBC3/MyODBC-3.51.06.exe"&gt;MyODBC-3.51.06.exe&lt;/a&gt; and install.&lt;br /&gt;&lt;br /&gt;Now add the following lines of code to connect it to the DataBase.&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;string sConString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=Lakhan; UID=root; PASSWORD=; OPTION=3";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        OdbcConnection oConnection = new OdbcConnection(sConString);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        string sSQL = "SELECT * FROM tdTest";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        OdbcDataAdapter oDataAdapter = new OdbcDataAdapter(sSQL, oConnection);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        DataSet oDataSet = new DataSet();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        oDataAdapter.Fill(oDataSet);&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;This piece of code will return a DataSet that contains data from tdTest Table.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-4935352815477431239?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/4935352815477431239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=4935352815477431239&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4935352815477431239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4935352815477431239'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/c-connectivity-with-mysql-using-odbc.html' title='C# Connectivity with MYSQL using ODBC'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1496993210703316968</id><published>2009-09-08T18:59:00.003+05:30</published><updated>2009-09-24T10:55:47.252+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><title type='text'>Regular Expression for Website URL</title><content type='html'>&lt;blockquote&gt;(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;amp;:/~\+#]*[\w\-\@?^=%&amp;amp;/~\+#])?&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote&gt;^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&amp;amp;%\$#\=~_\-]+))*$&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote&gt;/^((http(s?)|ftp))\:\/\/)?&lt;br /&gt;(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&amp;amp;%\$#\=~_\-]+))*$/&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1496993210703316968?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1496993210703316968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1496993210703316968&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1496993210703316968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1496993210703316968'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/regular-expression-for-website-url.html' title='Regular Expression for Website URL'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8839675053133578193</id><published>2009-09-08T18:36:00.001+05:30</published><updated>2009-09-24T11:02:58.206+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><title type='text'>Regular Expression for Password</title><content type='html'>&lt;blockquote&gt;^.*(?=.{10,})(?=.*\d)(?=.*[a-&lt;wbr&gt;z])(?=.*[A-Z])(?=.*[@#$%^&amp;amp;+=])&lt;wbr&gt;.*$&lt;/blockquote&gt;The regular expression enforces the following rules:&lt;br /&gt;* Must be at least 10 characters&lt;br /&gt;* Must contain at least one one lower case letter, one upper case letter, one digit and one  special character&lt;br /&gt;* Valid special characters (which are configurable) are -   @#$%^&amp;amp;+=&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]&lt;wbr&gt;).{4,8}$&lt;/blockquote&gt;&lt;span&gt;Password matching expression. Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8839675053133578193?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8839675053133578193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8839675053133578193&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8839675053133578193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8839675053133578193'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/regular-expression-for-password.html' title='Regular Expression for Password'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8440584837310890854</id><published>2009-09-08T18:27:00.003+05:30</published><updated>2009-09-24T11:06:51.754+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><title type='text'>Regular Expression for Email</title><content type='html'>&lt;blockquote&gt;/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/&lt;/blockquote&gt;&lt;blockquote&gt;^(([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)?(\.[a-zA-Z0-9_-]+))$&lt;/blockquote&gt;&lt;blockquote&gt;\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8440584837310890854?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8440584837310890854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8440584837310890854&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8440584837310890854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8440584837310890854'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/regular-expression-for-email.html' title='Regular Expression for Email'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-304282247308052914</id><published>2009-09-01T17:07:00.003+05:30</published><updated>2009-09-24T11:08:05.532+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Articles'/><title type='text'>JavaScript Object Notation (JSON)</title><content type='html'>&lt;span style="font-weight: bold;"&gt;JSON&lt;/span&gt; (&lt;a href="http://lakhangarg.blogspot.com/search/label/JavaScript"&gt;JavaScript&lt;/a&gt; Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. JSON is a language independent text format which is fast and easy to understand. JavaScript Object Notation (JSON) is a text format for the serialization of structured data. File extension for json file is *.json&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-weight: bold;"&gt;application/json&lt;/span&gt; is media type for &lt;a href="http://lakhangarg.blogspot.com/search/label/JavaScript"&gt;JavaScript&lt;/a&gt; Object Notation (JSON). JSON can represent &lt;span style="font-weight: bold;"&gt;four primitive types&lt;/span&gt;:&lt;br /&gt;•    Strings (double-quoted Unicode with backslash escaping)&lt;br /&gt;•    Numbers (integer, real, or floating point)&lt;br /&gt;•    Booleans (true and false)&lt;br /&gt;•    Null&lt;br /&gt;And &lt;span style="font-weight: bold;"&gt;two structured types&lt;/span&gt;:&lt;br /&gt;•    Objects (collection of key:value pairs, comma-separated and enclosed in curly braces)&lt;br /&gt;•    Arrays (an ordered sequence of values, comma-separated and enclosed in square brackets)&lt;br /&gt;&lt;br /&gt;A JSON text is a serialized object or array.&lt;br /&gt;&lt;br /&gt;JSON-text = object / array&lt;br /&gt;&lt;br /&gt;These are the six structural characters:&lt;br /&gt;&lt;br /&gt;begin-array    [ left square bracket&lt;br /&gt;&lt;br /&gt;begin-object   { left curly bracket&lt;br /&gt;&lt;br /&gt;end-array      ] right square bracket&lt;br /&gt;&lt;br /&gt;end-object     } right curly bracket&lt;br /&gt;&lt;br /&gt;name-separator  : colon&lt;br /&gt;&lt;br /&gt;value-separator , comma&lt;br /&gt;&lt;br /&gt;The following example shows the JSON representation of an object that describes a person. The object has string fields for first name and last name, contains an object representing the person's address, and contains a list of phone numbers (an array)&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: #009900;"&gt;.{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;     "firstName": "John",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;     "lastName": "Smith",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;     "address": {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;         "streetAddress": "21 2nd Street",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;         "city": "New York",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;         "state": "NY",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;         "postalCode": "10021"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;     },&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;     "phoneNumbers": [&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;         { "type": "home", "number": "212 555-1234" },&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;         { "type": "fax", "number": "646 555-4567" }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;     ]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt; }&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;The equivalent for the above in XML:&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: #009900;"&gt;&amp;lt;Person firstName="John" lastName="Smith"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;  &amp;lt;Address&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    &amp;lt;streetAddress&amp;gt;21 2nd Street&amp;lt;/streetAddress&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    &amp;lt;city&amp;gt;New York&amp;lt;/city&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    &amp;lt;state&amp;gt;NY&amp;lt;/state&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;    &amp;lt;postalCode&amp;gt;10021&amp;lt;/postalCode&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;  &amp;lt;/Address&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;  &amp;lt;phoneNumber type="home"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      212 555-1234&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;  &amp;lt;/phoneNumber&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;  &amp;lt;phoneNumber type="fax"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;      646 555-4567&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;  &amp;lt;/phoneNumber&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;lt;/Person&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;span style="font-weight: bold;"&gt;JSON is like &lt;a href="http://lakhangarg.blogspot.com/search/label/XML"&gt;XML&lt;/a&gt; because:&lt;/span&gt;&lt;br /&gt;1. They are both 'self-describing' meaning that values are named, and thus 'human readable'&lt;br /&gt;2. Both are hierarchical. (i.e. You can have values within values.)&lt;br /&gt;3. Both can be parsed and used by lots of programming languages&lt;br /&gt;4. Both can be passed around using AJAX (i.e. httpWebRequest)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;JSON is Unlike &lt;a href="http://lakhangarg.blogspot.com/search/label/XML"&gt;XML&lt;/a&gt; because:&lt;/span&gt;&lt;br /&gt;1. XML uses angle brackets, with a tag name at the start and end of an element: JSON uses squiggly brackets with the name only at the beginning of the element.&lt;br /&gt;2. JSON is less verbose so it's definitely quicker for humans to write, and probably quicker for us to read.&lt;br /&gt;3. JSON can be parsed trivially using the eval() procedure in JavaScript&lt;br /&gt;4. JSON includes arrays {where each element doesn't have a name of its own}&lt;br /&gt;5. In XML you can use any name you want for an element, in JSON you can't use reserved words from &lt;a href="http://lakhangarg.blogspot.com/search/label/JavaScript"&gt;JavaScript&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is good about JSON?&lt;/span&gt;&lt;br /&gt;When you're writing Ajax stuff, if you use JSON, then you avoid hand-writing xml. This is quicker.&lt;br /&gt;Again, when you're writing Ajax stuff, which looks easier? The XML approach or the JSON approach:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The &lt;a href="http://lakhangarg.blogspot.com/search/label/XML"&gt;XML&lt;/a&gt; approach:&lt;/span&gt;&lt;br /&gt;1. Bring back an XML document&lt;br /&gt;2. Loop through it, extracting values from it&lt;br /&gt;3. Do something with those values, etc,&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The JSON approach:&lt;/span&gt;&lt;br /&gt;1. Bring back a JSON string.&lt;br /&gt;2. 'eval' the JSON&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-304282247308052914?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/304282247308052914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=304282247308052914&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/304282247308052914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/304282247308052914'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/09/javascript-object-notation-json.html' title='JavaScript Object Notation (JSON)'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-9085738499521258603</id><published>2009-08-31T17:54:00.004+05:30</published><updated>2009-10-05T18:55:04.472+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Get the Number of Days in a Month for Given Month and Year</title><content type='html'>With this sample code user can get the number of days in the Given Month and Year.&lt;br /&gt;&lt;br /&gt;User's Input Data: '02-2009'  or '02/2009'&lt;br /&gt;&lt;br /&gt;There are two method to do this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;First Method:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: #009900;"&gt;DECLARE @Date varchar(20),@FirstDay varchar(2), @Seperator char(1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;SET @Date='02-2009'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;SET @FirstDay='01'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;SET @Seperator=SUBSTRING(@Date,3,1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;SET @Date=SUBSTRING(@Date,1,3) + @FirstDay + @Seperator + SUBSTRING(@Date,4,7)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;SELECT DATEDIFF(DAY,Convert(Datetime,@Date), DATEADD(MONTH,1,Convert(Datetime,@Date))) 'Days'&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: black;"&gt;Second Method:&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: #009900;"&gt;DECLARE @Date varchar(20),@Month int, @NextMonth varchar(20), @Year varchar(5),@Seperator char(1)&lt;br /&gt;DECLARE @FirstDay varchar(2)&lt;br /&gt;SET @Date='02-2009'&lt;br /&gt;SET @FirstDay='01'&lt;br /&gt;SET @Year=SUBSTRING(@Date,4,7)&lt;br /&gt;SET @Seperator=SUBSTRING(@Date,3,1)&lt;br /&gt;SET @Month =Convert(int,(SUBSTRING(@Date,1,2)))+1&lt;br /&gt;SET @Date=SUBSTRING(@Date,1,3)+@FirstDay+@Seperator+@Year&lt;br /&gt;IF(@Month&amp;gt;12)&lt;br /&gt;BEGIN&lt;br /&gt;SET @Month=1&lt;br /&gt;SET @Year=CONVERT(varchar(5), (CONVERT(int, @Year)+1))&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;SET @NextMonth=convert(varchar(2), @Month) + @Seperator + @FirstDay+@Seperator+@Year&lt;br /&gt;SELECT Convert(int,((Convert(Datetime,@NextMonth)) - (Convert(Datetime,@Date))))&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: black;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;span style="font-weight: bold;"&gt;Output:&lt;br /&gt;&lt;span style="color: black;"&gt;28 Days&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: black;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-9085738499521258603?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/9085738499521258603/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=9085738499521258603&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/9085738499521258603'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/9085738499521258603'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/get-number-of-days-in-month-for-given.html' title='Get the Number of Days in a Month for Given Month and Year'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8214869206862798940</id><published>2009-08-28T15:33:00.004+05:30</published><updated>2009-09-24T11:18:33.739+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Create XML Doc in C#</title><content type='html'>&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;This Sample code will show you how to create a XML document using C#.&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Suppose we have Data like:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;PublisherName: Wrox&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Book Subject: ASP.NET&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Book Title: &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;(1) Beginning ASP.NET MVC 1.0 &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;(2) Silverlight 3 Programmer's Reference &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;(3) Professional Refactoring in C# &amp;amp; ASP.NET&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Book Subject: SQL Server&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Book Title: &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;(1) Beginning Microsoft SQL Server 2008 Administration &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;(2) Professional LINQ&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;And we want to show this data in XML format:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Sample Code to show above Data into XMl Format:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;blockquote&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;XmlDocument xDoc = new XmlDocument();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndRootNode = xDoc.CreateElement("BookData");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        xDoc.AppendChild(ndRootNode);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndPublisher = xDoc.CreateElement("Publisher");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlAttribute atName = xDoc.CreateAttribute("Name");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        atName.Value = "Wrox";&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndPublisher.Attributes.Append(atName);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndRootNode.AppendChild(ndPublisher);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndBookSubject1 = xDoc.CreateElement("Subject");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlAttribute atSubject1 = xDoc.CreateAttribute("Name");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        atSubject1.Value = "ASP.NET";&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookSubject1.Attributes.Append(atSubject1)&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndPublisher.AppendChild(ndBookSubject1);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndBookTitle1 = xDoc.CreateElement("Title");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookTitle1.AppendChild(xDoc.CreateCDataSection("Beginning ASP.NET MVC 1.0"));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookSubject1.AppendChild(ndBookTitle1);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndBookTitle2 = xDoc.CreateElement("Title");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookTitle2.AppendChild(xDoc.CreateCDataSection("Silverlight 3 Programmer's Reference"));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookSubject1.AppendChild(ndBookTitle2);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndBookTitle3 = xDoc.CreateElement("Title");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookTitle3.AppendChild(xDoc.CreateCDataSection("Professional Refactoring in C# &amp;amp; ASP.NET"));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookSubject1.AppendChild(ndBookTitle3);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndBookSubject2 = xDoc.CreateElement("Subject");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlAttribute atSubject2 = xDoc.CreateAttribute("Name");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        atSubject2.Value = "SQL Server";&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookSubject1.Attributes.Append(atSubject2);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndPublisher.AppendChild(ndBookSubject2);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndBookTitle4 = xDoc.CreateElement("Title");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookTitle4.AppendChild(xDoc.CreateCDataSection("Beginning Microsoft SQL Server 2008 Administration"));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookSubject2.AppendChild(ndBookTitle4);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        XmlNode ndBookTitle5 = xDoc.CreateElement("Title");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookTitle5.AppendChild(xDoc.CreateCDataSection("Professional LINQ"));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;        ndBookSubject2.AppendChild(ndBookTitle5);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;div&gt;&amp;lt;BookData&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;Publisher Name="Wrox"&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;Subject Name="SQL Server"&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;Title&amp;gt;Beginning ASP.NET MVC 1.0&amp;lt;/Title&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;Title&amp;gt;Silverlight 3 Programmer's Reference&amp;lt;/Title&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;Title&amp;gt;Professional Refactoring in C# &amp;amp; ASP.NET&amp;lt;/Title&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;/Subject&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;Subject&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;Title&amp;gt;Beginning Microsoft SQL Server 2008 Administration&amp;lt;/Title&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;Title&amp;gt;Professional LINQ&amp;lt;/Title&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;/Subject&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;/Publisher&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;/BookData&amp;gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:arial;color:#009900;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:arial;color:#009900;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Georgia; font-weight: bold; "&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;The CreateCDataSection&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;span class="Apple-style-span"  style="color:#009900;"&gt;xDoc.CreateCDataSection("Beginning Microsoft SQL Server 2008 Administration")&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;is used to write the data in CData Section&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8214869206862798940?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8214869206862798940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8214869206862798940&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8214869206862798940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8214869206862798940'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/create-xml-doc-in-c.html' title='Create XML Doc in C#'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6587063948364307781</id><published>2009-08-21T15:16:00.002+05:30</published><updated>2009-08-21T16:04:44.207+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interview Tips'/><title type='text'>JavaScript Interview Questions</title><content type='html'>(1) Default setting for the expires attribute of the document.cookie property?&lt;br /&gt;Ans: The duration of the browser session.&lt;br /&gt;&lt;br /&gt;(2) &lt;span style="font-family:Arial;"&gt;Which JavaScript feature uses JAR files?&lt;br /&gt;Ans: Object signing&lt;br /&gt;&lt;br /&gt;(3) If onKeyDown event returns false, the key-press event is cancelled.&lt;br /&gt;&lt;br /&gt;(4) File is a Server-side JavaScript Object.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;(5) FileUpload is a Client-side JavaScript Object.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6587063948364307781?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6587063948364307781/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6587063948364307781&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6587063948364307781'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6587063948364307781'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/javascript-interview-questions.html' title='JavaScript Interview Questions'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1632299514118733955</id><published>2009-08-21T15:01:00.002+05:30</published><updated>2009-08-21T15:04:04.988+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>TextBox MaxLength Validation and Display Remaining Characters</title><content type='html'>&lt;span style="font-family: arial;"&gt;Text Box OR Text area max length validation and also display the words remaining.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Arguments:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(1) TextBox or Text Area ID&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(2) Label ID where we want to show count of remaining character.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(3) Number of Maximum character that are allowed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Sample Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;function CountCharactersGeneral(sourceTextBox, displayControl, maxLength)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;if(sourceTextBox != null &amp;amp;&amp;amp; displayControl != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;sourceTextBox = document.getElementById(sourceTextBox);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;displayControl = document.getElementById(displayControl);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;if(sourceTextBox != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var len = sourceTextBox.value.length&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;if (len&lt;=maxLength)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;displayControl.innerHTML = maxLength -len +" Character(s) remaining.";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;sourceTextBox.value = sourceTextBox.value.substring(0, maxLength);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;return false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1632299514118733955?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1632299514118733955/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1632299514118733955&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1632299514118733955'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1632299514118733955'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/textbox-maxlength-validation-and.html' title='TextBox MaxLength Validation and Display Remaining Characters'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-5825096189197983239</id><published>2009-08-21T14:53:00.002+05:30</published><updated>2009-08-21T15:00:15.851+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Show Current - Date,Month,Year in JavaScript</title><content type='html'>&lt;span style="font-family: arial;"&gt;This Code will return the Result in numeric form as :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;for date 21/8/2009:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;objDate.getDate();   will return 21.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;objDate.getMonth() + 1 will return 8&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;objDate.getFullYear() will return 2009&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var objDate=new Date();   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var today=objDate.getDate();  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var month=objDate.getMonth() + 1;   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var year=objDate.getFullYear(); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Sample Code To Show Today's Detail:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var months = new Array(12);   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[0]="January";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[1]="February"; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[2]="March";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[3]="April";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[4]="May";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[5]="June";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[6]="July";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[7]="August";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[8]="September";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[9]="October"; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[10]="November";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;months[11]="December";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var days = new Array(7);   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;days[0]="Sunday";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;days[1]="Monday";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;days[2]="Tuesday";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;days[3]="Wednesday"; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;days[4]="Thursday";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;days[5]="Friday";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;days[6]="Saturday";   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var objDate=new Date();   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var today=objDate.getDay();  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var date=objDate.getDate(); &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var month=objDate.getMonth();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;var year=objDate.getFullYear();   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;document.write("Today is :   " + days[today] + ",   " + months[month] + "  " + date+ ", " + year);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-family: arial;"&gt;document.write("Current date is :   " + today + " / " + month + " / " + year); &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-5825096189197983239?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/5825096189197983239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=5825096189197983239&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5825096189197983239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5825096189197983239'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/show-current-datemonthyear-in.html' title='Show Current - Date,Month,Year in JavaScript'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6536987806145411343</id><published>2009-08-21T14:50:00.000+05:30</published><updated>2009-08-21T14:52:26.705+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Display Random Message on Page Refresh</title><content type='html'>Show Rendom Message On Page refresh.&lt;br /&gt;Place all the Messages in an Array&lt;br /&gt;Math.floor(Math.random() * 8) function will pick the random record from array.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample Code:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&amp;lt;script language="JavaScript" type="text/javascript"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   var arMessage = new Array(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   'She is a complete waste of space',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   'I did not recognize you with your clothes on ',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   'If I never see you again, it will be too soon ',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   'He is so full of shit, even his eyes are brown',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   'You are so far up our managers ass, I can almost see your legs',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   'She is as welcome as a turd in a swimmingpool',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   'My boss is an accident waiting for a place to happen',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   'I would not piss on you, even when you were on fire');&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   var ind = Math.floor(Math.random() * 8);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   document.write('&amp;lt;b class="r"&amp;gt;'+arMessage[ind]+'&amp;lt;/b&amp;gt;');&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6536987806145411343?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6536987806145411343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6536987806145411343&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6536987806145411343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6536987806145411343'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/display-random-message-on-page-refresh.html' title='Display Random Message on Page Refresh'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6189430712232023715</id><published>2009-08-21T14:46:00.003+05:30</published><updated>2009-08-21T14:52:50.781+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>Code to Create Own Currency Convertor</title><content type='html'>&lt;span style="font-family:arial;"&gt;XML Based Currency Converter&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample Code:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;using System.Xml;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;private void ReadXMLData(string SourceCountry, string DestCountry)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        double Amount = 10;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        string SourceCode = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        double SourceCountryValue=0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        double DestCountryValue=0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        string DestCode = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        XmlDocument xmlDoc = new XmlDocument();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        xmlDoc.Load(Server.MapPath("Convertor.xml"));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        XmlNodeList xmlList= xmlDoc.GetElementsByTagName("Country");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        for (Int16 iCount = 0; iCount &lt;&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            if (xmlList.Item(iCount).Attributes.GetNamedItem("name").InnerText == SourceCountry)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                SourceCountryValue = Convert.ToDouble(xmlList.Item(iCount).Attributes.GetNamedItem("value").InnerText);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                SourceCode = xmlList.Item(iCount).Attributes.GetNamedItem("CurrencyCode").InnerText;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            else if (xmlList.Item(iCount).Attributes.GetNamedItem("name").InnerText == DestCountry)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                DestCountryValue = Convert.ToDouble(xmlList.Item(iCount).Attributes.GetNamedItem("value").InnerText);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                DestCode = xmlList.Item(iCount).Attributes.GetNamedItem("CurrencyCode").InnerText;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        Response.Write(Amount.ToString()+ " "+SourceCode +"=" +Convert.ToString(Amount * (DestCountryValue / SourceCountryValue)));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Call the above Method Like This: ReadXMLData("UK", "India");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;a href="http://www.dotnetspider.com/attachments/Resources/28179-4444-Convertor.xml"&gt;Click Here&lt;/a&gt; to get the Sample Data.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6189430712232023715?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6189430712232023715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6189430712232023715&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6189430712232023715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6189430712232023715'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/code-to-create-own-currency-convertor.html' title='Code to Create Own Currency Convertor'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-4521029325973213901</id><published>2009-08-21T14:41:00.003+05:30</published><updated>2009-08-21T14:45:58.557+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Clear value of controls on a page</title><content type='html'>This Code is used to clear the value of TextBox, DropDownList, CheckBox, CheckBoxList controls available in any container control.&lt;br /&gt;&lt;br /&gt;in this Sample Code we need to pass the instance of the form (Page obj) and the Container Control's ID.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;public static void ClearControls( Page obj, string strContentHolder)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;foreach (Control c in obj.Master.FindControl (strContentHolder).Controls)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;TextBox t = (TextBox)c;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;t.Text ="";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;if (c.GetType().ToString().Equals("System.Web.UI.WebControls.DropDownList"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;DropDownList ddl = (DropDownList)c;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;ddl.SelectedIndex = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;if (c.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;CheckBox chk = (CheckBox)c;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;chk.Checked =false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;if (c.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBoxList"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;CheckBoxList chkList = (CheckBoxList)c;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;for (int i = 0; i &lt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;chkList.Items[i].Selected =false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-4521029325973213901?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/4521029325973213901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=4521029325973213901&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4521029325973213901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4521029325973213901'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/clear-value-of-controls-on-page.html' title='Clear value of controls on a page'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-7485433018059778028</id><published>2009-08-17T17:03:00.007+05:30</published><updated>2009-08-17T17:57:14.353+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Implement Multilingual in ASP.NET Web Site using globalization.</title><content type='html'>Before going to implement  we need to know the answer of few question:&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;What is globalization?&lt;/span&gt;&lt;br /&gt;Globalization is the process of making an application that supports multiple cultures without mixing up the business logic and the culture related information of that application.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;What&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; is localization?&lt;/span&gt;&lt;br /&gt;In Localization you customize the application for new locales. This consists of translating resources that you identified during the globalization phase.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is Local Resource?&lt;/span&gt;&lt;br /&gt;File which stores resources with local scope into App_LocalResource directory. We can not access one pages local resource from another page.&lt;br /&gt;They can be generated by ASP.Net automatically. For it go to design view of aspx page and then Tools &gt; Generate&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is Global Resource?&lt;/span&gt;&lt;br /&gt;File used to store resources globally, means we can access same resource from different pages. It store in App_GlobalResource folder. we can't generate global resource automatically.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Difference between Local Resource and Global Resource:&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Performance: Global Resources are faster than Local Resource- because Global Resources are Strongly Typed.&lt;/li&gt;&lt;li&gt;Consistency. Explanation: In your application you have Label Text as Category and ten pages. Now you want to change it to CATEGORY then if you using Local Resource concept then you have to change 10 resource files, where as in Global Resource you need to change only one.&lt;/li&gt;&lt;li&gt;Difference as per Project Type:&lt;ul&gt;&lt;li&gt;                                Local Resource is treated as content based resource, so we can change it and it affects    to website.&lt;/li&gt;&lt;li&gt;                               Global Resource is treated as embedded resource, So they are compiled into specific language dlls into bin folder.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-weight: bold;"&gt;Code to implement multilingual using global resource:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Add This in global.asax file:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;private void Application_BeginRequest(Object source, EventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        string[] languages = HttpContext.Current.Request.UserLanguages;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        if (languages[0].ToLower() != null &amp;amp;&amp;amp; languages[0].ToLower()!="")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(languages[0].ToLower());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(languages[0].ToLower());&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;now we can use resource file on page like this:&lt;br /&gt;suppose  we have three resource file in app_globalresource folder:&lt;br /&gt;TestResource.resx (Default)&lt;br /&gt;TestResource.hi.resx (Hindi)&lt;br /&gt;TestResource.zn-ch.resx (Chinese)&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;:Label ID="lblText" runat="server" Text="&lt;%$ Resources:TestResource, LabelText %&amp;amp;&gt;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;now as we set the language from browser, the text for label will be read from respected files.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-7485433018059778028?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/7485433018059778028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=7485433018059778028&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7485433018059778028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7485433018059778028'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/implementation-multilingual-in-aspnet.html' title='Implement Multilingual in ASP.NET Web Site using globalization.'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-4941691309396559597</id><published>2009-08-05T14:42:00.002+05:30</published><updated>2009-08-05T14:53:39.284+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Get Median value from SQL Server Table</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Sample code to get the median of table data in SQL Server. Declare two variables first to get the number of rows and second to store median value.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;DECLARE @Count int,@Median Float&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to get the number of rows:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;SELECT @Count=COUNT(*) FROM  (&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;SELECT ID,COUNT(ID) AS IDCount FROM MyTable GROUP BY ID)AB&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;if the number of rows are even then query to get the median value is:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;SELECT @Median=(SUM(Convert(float,IDCount))/2) FROM(SELECT ID,COUNT(ID)AS IDCount,ROW_NUMBER() OVER(ORDER BY COUNT(ID))AS ROW &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        FROM MyTable GROUP BY ID)AB&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        WHERE AB.Row IN ((@Count/2),(@Count/2)+1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to get the median in case of odd rows:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;SELECT @Median=IDCount FROM(SELECT ID,COUNT(ID)AS IDCount,ROW_NUMBER() OVER(ORDER BY COUNT(ID))AS ROW &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        FROM MyTable GROUP BY ID)AB&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        WHERE AB.Row =((@Count/2)+1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Sample Query:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;DECLARE @Count int,@Median Float&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;SELECT @Count=COUNT(*) FROM  (&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;SELECT ID,COUNT(ID) AS IDCount FROM MyTable GROUP BY ID)AB&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;DECLARE @SQLQuery varchar(500)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;IF(@Count%2=0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;    BEGIN    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        SELECT @Median=(SUM(Convert(float,IDCount))/2) FROM(SELECT ID,COUNT(ID)AS IDCount,ROW_NUMBER() OVER(ORDER BY COUNT(ID))AS ROW &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        FROM MyTable GROUP BY ID)AB&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        WHERE AB.Row IN ((@Count/2),(@Count/2)+1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;    END&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;ELSE&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;    SELECT @Median=IDCount FROM(SELECT ID,COUNT(ID)AS IDCount,ROW_NUMBER() OVER(ORDER BY COUNT(ID))AS ROW &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        FROM MyTable GROUP BY ID)AB&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;        WHERE AB.Row =((@Count/2)+1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:arial;" &gt;SELECT @Median&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-4941691309396559597?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/4941691309396559597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=4941691309396559597&amp;isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4941691309396559597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4941691309396559597'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/08/get-median-from-table-data.html' title='Get Median value from SQL Server Table'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2208127999706518222</id><published>2009-07-29T18:55:00.008+05:30</published><updated>2009-07-30T17:14:20.749+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Articles'/><title type='text'>HTTP Request Message Format</title><content type='html'>&lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style=""&gt;Key Concept: &lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=""&gt;HTTP requests&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; are the means by which HTTP clients ask servers to take a particular type of action, such as sending a file or processing user input. Each request message begins with a &lt;i&gt;request line&lt;/i&gt;, which contains three critical pieces of information: the &lt;i&gt;method&lt;/i&gt; (type of action) the client is requesting; the &lt;i&gt;URI&lt;/i&gt; of the resource upon which the client wishes the action to be performed, and the version of HTTP that the client is using. After the request line come a set of message headers related to the request, followed by a blank line and then optionally, the message body of the request.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;The client initiates an HTTP session by opening a TCP connection to the HTTP server with which it wishes to communicate. It then sends &lt;i&gt;request messages&lt;/i&gt; to the server, each of which specifies a particular type of action that the user of the HTTP client would like the server to take. Requests can be generated either by specific user action (such as clicking a hyperlink in a Web browser) or indirectly as a result of a prior action (such as a reference to an inline image in an HTML document leading to a request for that image.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;HTTP requests use a message format that is based on the generic message format described in &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_HTTPGenericMessageFormat.htm"&gt;&lt;span style=""&gt;the preceding topic&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;, but specific to the needs of requests. The structure of this format is as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.tcpipguide.com/free/diagrams/httprequest.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 454px; height: 199px;" src="http://www.tcpipguide.com/free/diagrams/httprequest.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;This diagram shows the structural elements of an HTTP request and an example of the sorts of headers a request might contain. Like most HTTP requests, this one carries no entity, so there are no entity headers and the message body is empty.&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;i&gt;&lt;span style=""&gt;Request Line&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;The generic &lt;i&gt;start line&lt;/i&gt; that begins all HTTP messages is called a &lt;i&gt;request line&lt;/i&gt; in request messages. It has a three-fold purpose: to indicate the command or action that the client wants performed; to specify a resource upon which the action should be taken; and to indicate to the server what version of HTTP the client is using. The formal syntax for the request line is:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;method&gt; &lt;request-uri&gt; &lt;http-version&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/http-version&gt;&lt;/request-uri&gt;&lt;/method&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 0.0001pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style=""&gt;Method&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;The &lt;i&gt;method&lt;/i&gt; is simply the type of action that the client wants the server to take; it is always specified in upper case letters. There are eight standard methods defined in HTTP/1.1, of which three are widely used: &lt;i&gt;GET&lt;/i&gt;, &lt;i&gt;HEAD&lt;/i&gt; and &lt;i&gt;POST&lt;/i&gt;. They are called “methods” rather than “commands” because the HTTP standard uses terminology from object-oriented programming. I explain this and also describe the methods themselves in &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_HTTPMethods.htm"&gt;&lt;span style=""&gt;the topic describing HTTP methods&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 0.0001pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style=""&gt;Request URI&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;The &lt;i&gt;request URI&lt;/i&gt; is the &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_TCPIPApplicationLayerAddressingUniformResourceIden.htm"&gt;&lt;span style=""&gt;uniform resource identifier&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; of the resource to which the request applies. While URIs can theoretically refer to either &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_UniformResourceLocatorsURLs.htm"&gt;&lt;span style=""&gt;uniform resource locators (URLs)&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; or &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_UniformResourceNamesURNs.htm"&gt;&lt;span style=""&gt;uniform resource names (URNs)&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;, at the present time a URI is almost always an &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_WorldWideWebAddressingHTTPUniformResourceLocatorsU.htm"&gt;&lt;span style=""&gt;HTTP URL that follows the standard syntax rules of Web URLs&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;. &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Interestingly, the exact form of the URL used in the HTTP request line usually differs from that used in HTML documents or entered by users. This is because some of the information in a full URL is used to control HTTP itself. It is needed as part of the communication between the user and the HTTP client, but not in the request from the client to the server. The standard method of specifying a resource in a request is to include the path and file name in the request line (as well as any optional query information) while specifying the host in the special &lt;i&gt;Host&lt;/i&gt; header that must be used in HTTP/1.1 requests. &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;For example, suppose the user enters a URL such as this:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;http://www.myfavoritewebsite.com:8080/chatware/chatroom.php&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;We obviously don't need to send the “http:” to the server. The client would take the remaining information and split it so the URI was specified as “/chatware/chatroom.php” and the &lt;i&gt;Host&lt;/i&gt; line would contain “www.myfavoritewebsite.com:8080”. Thus, the start of the request would look like this:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;GET /chatware/chatroom.php HTTP/1.1&lt;br /&gt;Host: www.myfavoritewebsite.com:8080&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;The exception to this rule is when a request is being made to a &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_HTTPProxyServersandProxying.htm"&gt;&lt;span style=""&gt;proxy server&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;. In that case, the request is made using the full URL in its original form, so that it can be processed by the proxy just as the original client did. The request would be:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 5pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;GET http://www.myfavoritewebsite.com:8080/chatware/chatroom.php HTTP/1.1&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Finally, there is one special case where a single asterisk can be used instead of a real URL. This is for the &lt;i&gt;OPTIONS&lt;/i&gt; method, which does not require the specification of a resource. (Nominally, the asterisk means the method refers to the server itself.)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="margin-bottom: 0.0001pt; line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style=""&gt;HTTP Version&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;The &lt;i&gt;HTTP-VERSION&lt;/i&gt; element tells the server what version the client is using so the server knows how to interpret the request, and what to send and not to send the client in its response. For example, a server receiving a request from a client using versions 0.9 or 1.0 will assume that a &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_HTTPTransitoryandPersistentConnectionsandPipelinin.htm"&gt;&lt;span style=""&gt;transitory connection is being used rather than a persistent one&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;, and will avoid using version 1.1 headers in its reply. The version token is sent in upper case as “HTTP/0.9”, “HTTP/1.0” or “HTTP/1.1”—just the way I've been doing throughout my discussion of the protocol.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;i&gt;&lt;span style=""&gt;Headers&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;After the request line come any of the headers that the client wants to include in the message; it is in these headers that details are provided to the server about the request. The headers all use the same structure, but are organized into categories based on the functions they serve, and whether they are specific to one kind of message or not&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style=""&gt;General Headers:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; General headers refer mainly to the message itself, as opposed to its contents, and are used to control its processing or provide the recipient with extra information. They are not particular to either request or response messages, so they can appear in either. They are likewise not specifically relevant to any entity the message may be carrying.&lt;/span&gt;&lt;span style="font-size:100%;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul  type="circle" style="font-family:arial;"&gt;&lt;li class="MsoNormal" style="margin-bottom: 12pt; line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style=""&gt;Request Headers:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;      These headers convey to the server more details about the nature of the      client's request, and give the client more control over how the request is      handled. For example, special request headers can be used by the client to      specify a conditional request—one that is only filled if certain criteria      are met. Others can tell the server which formats or encodings the client      is able to process in a response message.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="line-height: normal;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style=""&gt;Entity Headers:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;      These are headers that describe the entity contained in the body of the      request, if any.&lt;/span&gt;&lt;span style="font-size:100%;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Request headers are obviously used only in request messages, but both general headers and entity headers can appear in either a request or a response message. Since there are so many headers and most are not particular to one message type, they are described in detail in &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.tcpipguide.com/free/t_HTTPMessageHeaders.htm"&gt;&lt;span style=""&gt;their own complete section&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Info Collected from :&lt;a href="http://www.tcpipguide.com/free/t_HTTPRequestMessageFormat.htm"&gt; http://www.tcpipguide.com/free/t_HTTPRequestMessageFormat.htm&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="line-height: normal;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2208127999706518222?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2208127999706518222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2208127999706518222&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2208127999706518222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2208127999706518222'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/http-request-message-format.html' title='HTTP Request Message Format'/><author><name>Puneet Sharma</name><uri>http://www.blogger.com/profile/14730391898378869483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_fFHh4k4iaYI/SauFRpna1uI/AAAAAAAAAbA/6IEyp3OjJSM/S220/Puneet1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8208062408002123144</id><published>2009-07-28T16:47:00.004+05:30</published><updated>2009-08-21T15:15:58.198+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interview Tips'/><title type='text'>Dot Net Interview Tips</title><content type='html'>&lt;ol&gt;&lt;li&gt;Data that can be stored in a cookie?                                                                                                           4 KB/2096 Bytes&lt;/li&gt;&lt;li&gt;Most Browsers provides a limit of storing cookies is 20. If new cookie came, it will discard the old one but some of browser support up to 300 cookies.&lt;/li&gt;&lt;li&gt;Persistent Cookies can be called as permanent cookie.  Which is stored in client hard drive until it expires. While non persistent cookies can be called as temporary cookies, if there is no expire time defined then the cookie is stored in the browser’s memory.&lt;/li&gt;&lt;li&gt; Difference in persistence and non persistence cookies is persistence cookies should have an expiration time defined within it.&lt;/li&gt;&lt;li&gt;Where does cookies are stored in local hard drive?                                                         C:\Documents and Settings\{Current Login User}\Cookies&lt;/li&gt;&lt;li&gt;To expire the persistent cookies before its expiration time the expiration time as the Now.DateTime.AddDays(-1);&lt;/li&gt;&lt;li&gt;‘&lt;span style="font-weight: bold;"&gt;Cookie Munging&lt;/span&gt;’ is a concept of ASP.Net which lets users to manage session variables if their browsers do not support cookies. By default, ASP.Net uses cookies to store session ID’s. But, as we all know that some browsers do not support cookies. To overcome from this ASP.Net uses ‘Cookie Munging’ to manage session variables without cookies.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Cookie Munging&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; works? &lt;/span&gt;&lt;br /&gt;When user requests page from server ASP.Net adds encoded session ID to every href in page. When user clicks a link ASP.Net decodes that encoded session ID and passes it back to the page the user is requesting. Now, the requesting page can use that ID to set or retrieve any session variables. This all happens automatically, if asp.net detects that the users browser do not support cookies.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8208062408002123144?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8208062408002123144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8208062408002123144&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8208062408002123144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8208062408002123144'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/dot-net-interview-tips.html' title='Dot Net Interview Tips'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8037712618449130277</id><published>2009-07-18T12:51:00.008+05:30</published><updated>2010-05-28T12:01:13.180+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Excel Sheet Import/Export'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Read, Insert and Update Data into Excel Sheet</title><content type='html'>This application will tell you about the operation on excel sheet (like Insert, Update and Read) with the help of simple queries.&lt;br /&gt;i am using &lt;span style="font-weight: bold;"&gt;OLEDB&lt;/span&gt; provider for these operations.&lt;br /&gt;Connection String for OLEDB is:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;string file = Server.MapPath("UserData.xls"); string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file + ";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;Extended Properties=Excel 8.0;";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Read data and display the result in repeater control:&lt;br /&gt;First we'll read the data from the Excel sheet and display the result into a repeater control.&lt;br /&gt;first query to fetch the records:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;string query = "Select UserID,UserName,Country,State,City from [Sheet1$]";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[Sheet1$]&lt;/span&gt; name of the sheet in the Excel workbook.And UserID,UserName,Country,State,City are the name of the column in this sheet.&lt;br /&gt;this query will return all the records from Excel Sheet [Sheet1$].&lt;br /&gt;Code to execute the above query is:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;DataSet dsUserData = new DataSet();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;using (OleDbConnection Connection = new OleDbConnection(constr))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;using (OleDbDataAdapter DataAdapter = new OleDbDataAdapter(query, Connection))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;DataAdapter.Fill(dsUserData, "UserData");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;DataAdapter.AcceptChangesDuringFill = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;DataAdapter.Dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;Connection.Close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Update Data:&lt;/span&gt;&lt;br /&gt;we can click on the Edit Data link for the corresponding row to edit the record.&lt;br /&gt;on click of Edit Data button the corresponding records data will be shown in textboxes. user can change the text and click on the "Update Excel Data" to reflect changes is Excel Sheet.&lt;br /&gt;Code to Update Record:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;string file = Server.MapPath("UserData.xls");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file + ";Extended Properties=Excel 8.0;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;using (OleDbConnection Connection = new OleDbConnection(constr))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;Connection.Open();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;string query = "UPDATE [Sheet1$] SET UserName=\"" + txtUserName.Text.Trim() + "\",Country=\"" + txtCountry.Text.Trim() + "\",State=\"" + txtState.Text.Trim() + "\",City=\"" + txtCity.Text.Trim() + "\" WHERE UserID="+ btnUpdate.CommandArgument.ToString();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;using (OleDbCommand objCmd = new OleDbCommand(query, Connection))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;objCmd.ExecuteNonQuery();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;objCmd.Dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;Connection.Close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Similar way we can add the new record into the Excel Sheet. first we will get the UserId of the Last record and add one to that record to get the next UserID as:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #009900; font-style: italic;"&gt;Int32 LastUserID = Convert.ToInt32(((Label)rptUserData.Items[rptUserData.Items.Count - 1].FindControl("lblID")).Text);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="color: #009900;"&gt;LastUserID += 1;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://www.dotnetspider.com/attachments/Projects/545-17811-ExcelOperation.zip"&gt;&lt;strong&gt;Click Here To Download Source Code&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Note:&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Please contact me in case you have any error in download the code: &lt;/span&gt;&lt;a href="mailto:lakhangarg@gmail.com" style="font-style: italic; font-weight: bold;"&gt;lakhangarg@gmail.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size: large;"&gt;Note: &lt;/span&gt;&lt;u&gt;User the Following Connection String for xlsx file: &lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + file + ";Extended Properties=Excel 12.0;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8037712618449130277?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8037712618449130277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8037712618449130277&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8037712618449130277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8037712618449130277'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/read-insert-and-update-data-into-excel.html' title='Read, Insert and Update Data into Excel Sheet'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1992736682254165790</id><published>2009-07-18T12:30:00.007+05:30</published><updated>2009-07-21T18:14:32.495+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Sorting in Repeater Control</title><content type='html'>To implement sorting in repeater control first add the column name as link button:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;asp:LinkButton ID="lnkUserName" runat="server" CommandName="UserName"&amp;gt;User Name&amp;lt;/asp:LinkButton&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Please Note : &lt;/span&gt;&lt;span&gt;Command Name Should be Same as the name of the column in your Datatable.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this app we are using ViewState to Store the Column name and the Sort Order.&lt;br /&gt;&lt;span style="font-style: italic;"&gt;ViewState["Column"] &amp;amp; ViewState["Order"] &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Purpose of using the CommandName same as of Column name to avoid more hardcoding and to make application simple.&lt;br /&gt;&lt;br /&gt;we can simply get the column name from e.CommanName.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;u&gt;Sample Code&lt;/u&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System.Data;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System.Configuration;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System.Web;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System.Web.Security;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System.Web.UI;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System.Web.UI.WebControls;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System.Web.UI.WebControls.WebParts;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;using System.Web.UI.HtmlControls;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;public partial class _Default : System.Web.UI.Page &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    protected void Page_Load(object sender, EventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        if (!IsPostBack)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            //Set View State Value for Initial Sort Order&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            ViewState["Column"] = "UserName";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            ViewState["Order"] = "ASC";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            //Call To Method to Bind Repeater&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            BindRepeater();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// Bind Repeater with the Data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    private void BindRepeater()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataTable dtData = GetData();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataView dvData = new DataView(dtData);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        //Sorting Filter&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dvData.Sort = ViewState["Column"].ToString() + " " + ViewState["Order"].ToString();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        rptUserData.DataSource = dvData;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        rptUserData.DataBind();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtData.Dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dvData.Dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// Method To Get Data in the form of DataTable&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// &amp;lt;returns&amp;gt;DataTable&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    private DataTable GetData()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataTable dtNew = new DataTable();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataColumn dcUserName = new DataColumn("UserName");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Columns.Add(dcUserName);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataColumn dcAge = new DataColumn("Age");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Columns.Add(dcAge);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataColumn dcCountry = new DataColumn("Country");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Columns.Add(dcCountry);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataColumn dcState = new DataColumn("State");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Columns.Add(dcState);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataColumn dcCity = new DataColumn("CityName");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Columns.Add(dcCity);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        DataRow dr;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr = dtNew.NewRow();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["UserName"] = "Lakhan Pal Garg";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Age"] = "26";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Country"] = "India";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["State"] = "Punjab";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["CityName"] = "Chandigarh";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Rows.Add(dr);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr = dtNew.NewRow();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["UserName"] = "Naveen Garg";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Age"] = "24";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Country"] = "Canada";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["State"] = "Ontario";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["CityName"] = "Toronto";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Rows.Add(dr);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr = dtNew.NewRow();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["UserName"] = "Amrik Singh";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Age"] = "28";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Country"] = "India";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["State"] = "Haryana";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["CityName"] = "Pehowa";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Rows.Add(dr);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr = dtNew.NewRow();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["UserName"] = "Puneet Sharma";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Age"] = "25";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Country"] = "England";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["State"] = "Rutland";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["CityName"] = "Oakham";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Rows.Add(dr);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr = dtNew.NewRow();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["UserName"] = "Avinash";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Age"] = "40";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["Country"] = "USA";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["State"] = "New York";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dr["CityName"] = "Albany";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        dtNew.Rows.Add(dr);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        return dtNew;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// Repeater's Item Command Event&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// In this we will set the Column name and sorting Order for the selected column.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    protected void rptUserData_ItemCommand(object source, RepeaterCommandEventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        if (e.CommandName == ViewState["Column"].ToString())&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            if (ViewState["Order"].ToString() == "ASC")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;                ViewState["Order"] = "DESC";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;                ViewState["Order"] = "ASC";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            ViewState["Column"] = e.CommandName;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;            ViewState["Order"] = "ASC";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        //Call To Method to Bind Repeater&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;        BindRepeater();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.dotnetspider.com/attachments/Projects/541-16824-SortingApp.zip"&gt;&lt;strong&gt;Click Here To Download Source Code&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Note:&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Please contact me in case you have  any error in download the code: &lt;/span&gt;&lt;a style="font-style: italic; font-weight: bold;" href="mailto:lakhangarg@gmail.com"&gt;lakhangarg@gmail.com&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1992736682254165790?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1992736682254165790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1992736682254165790&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1992736682254165790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1992736682254165790'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/sorting-in-repeater-control.html' title='Sorting in Repeater Control'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6812249870518048077</id><published>2009-07-16T14:31:00.002+05:30</published><updated>2009-07-21T18:15:17.399+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>SCOPE_IDENTITY() v/s @@IDENTITY</title><content type='html'>&lt;span style="font-weight: bold;font-family:arial;" &gt;&lt;u&gt;SCOPE_IDENTITY() v/s @@IDENTITY&lt;/u&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Both &lt;span style="font-style: italic;"&gt;SCOPE_IDENTITY()&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;@@IDENTITY&lt;/span&gt; will return the last identity value generated in the table. but there is some difference between the two:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="font-weight: bold;"&gt;SCOPE_IDENTITY()&lt;/span&gt; will return the Identity value generated in a table that is currently in scope.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="font-weight: bold;"&gt;@@IDENTITY&lt;/span&gt; will return the Identity value generated in a table irrespective of the scope.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;For Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;Let us suppose we have two tables named table1 &amp;amp; table2... and we have one trigger defined on table1 that is insert a record in table2 when new record will be inserted into table1.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;in this case the Output of Both SCOPE_IDENTITY() and @@IDENTITY will be different.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;SCOPE_IDENTITY() will return the identity value of table1 that is in current scope.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;while @@IDENTITY will return the identity value of table2.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6812249870518048077?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6812249870518048077/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6812249870518048077&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6812249870518048077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6812249870518048077'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/scopeidentity-vs-identity.html' title='SCOPE_IDENTITY() v/s @@IDENTITY'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-5350998926126940838</id><published>2009-07-15T14:53:00.003+05:30</published><updated>2009-07-21T18:21:53.789+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Create Thumbnail</title><content type='html'>&lt;span style="font-family:arial;"&gt;This Code will help the users to create thumbnail of an image. for this user need to pass three parameters as:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;(1) Image To Scale&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;(2) Desired height of the output image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;(3) Desired width of output image&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;First we will get the image in a Bitmap Object and then we will scale the image.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;u style="font-family: arial; font-weight: bold;"&gt;Here is the Code to create thumbnail&lt;/u&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:arial;"&gt;/// Scales an image as per the ratio of dimensions of the image to hight and width specified in the&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        /// parameters&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;        &lt;span style="color: rgb(0, 153, 0);"&gt;public static System.Drawing.Image ScaleByPercent(string strImage, double dblImgHt, double dblImgWd)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;            Bitmap imgRetPhoto = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;            double dblWdRatio, dblHtRatio;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;            try&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                imgRetPhoto = new Bitmap(strImage);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                if (imgRetPhoto.Height &amp;gt; Convert.ToInt32(dblImgHt) || imgRetPhoto.Width &amp;gt; Convert.ToInt32(dblImgWd))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                    if (imgRetPhoto.Height &amp;gt; dblImgHt)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                        dblHtRatio = dblImgHt / Convert.ToDouble(imgRetPhoto.Height);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                        dblWdRatio = Convert.ToDouble(imgRetPhoto.Width) * dblHtRatio;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                        imgRetPhoto = new Bitmap(imgRetPhoto, Convert.ToInt32(dblWdRatio), Convert.ToInt32(dblImgHt));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                        imgRetPhoto.SetResolution(imgRetPhoto.HorizontalResolution, imgRetPhoto.VerticalResolution);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                    if (imgRetPhoto.Width &amp;gt; dblImgWd)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                        dblWdRatio = dblImgWd / Convert.ToDouble(imgRetPhoto.Width);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                        dblHtRatio = Convert.ToDouble(imgRetPhoto.Height) * dblWdRatio;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                        imgRetPhoto = new Bitmap(imgRetPhoto, Convert.ToInt32(dblImgWd), Convert.ToInt32(dblHtRatio));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                        imgRetPhoto.SetResolution(imgRetPhoto.HorizontalResolution, imgRetPhoto.VerticalResolution);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                    return imgRetPhoto;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                    return imgRetPhoto;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;            catch (Exception ex)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;                throw ex;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-family:arial;" &gt;        }&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-5350998926126940838?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/5350998926126940838/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=5350998926126940838&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5350998926126940838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5350998926126940838'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/create-thumbnail.html' title='Create Thumbnail'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2795857313300851433</id><published>2009-07-15T11:16:00.007+05:30</published><updated>2009-07-21T18:28:09.342+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Function To Get Tabular Data From a Delimilted String Variable</title><content type='html'>&lt;span style="font-family: arial;font-family:times new roman;font-size:100%;"  &gt;In this there are two input variables. first is delimited string variable and the second is delimited character.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:100%;"  &gt;&lt;span style="font-weight: bold;"&gt;&lt;u&gt;Sample Code&lt;/u&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;CREATE FUNCTION [dbo].[function_string_to_table]&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;(&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;    @string VARCHAR(7999),&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;    @delimiter CHAR(1)&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;)&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;RETURNS @output TABLE(&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;    data VARCHAR(256)&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;)&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;BEGIN&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;    DECLARE @start INT, @end INT&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;" &gt;&lt;span style=";font-family:times new roman;font-size:85%;"  &gt;    WHILE @start &lt;&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;        IF @end = 0 &lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;            SET @end = LEN(@string) + 1&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;        INSERT INTO @output (data) &lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;        VALUES(LTRIM(RTRIM(SUBSTRING(@string, @start, @end - @start))))&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;        SET @start = @end + 1&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;        SET @end = CHARINDEX(@delimiter, @string, @start)&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;    END&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;    RETURN&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;span style=";font-family:times new roman;font-size:85%;"  &gt;END&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:arial;" &gt;&lt;span style="font-family:arial;"&gt;&lt;span style="color: rgb(0, 0, 0);font-family:times new roman;" &gt;Suppose we have string variable like:'1,2,3,4,5'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);font-family:times new roman;" &gt;and in this the delimiter character is comma ','&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);font-family:times new roman;" &gt;if we call this as:&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;SELECT [dbo].[function_string_to_table]('1,2,3,4,5',',')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Output of this will be :&lt;/span&gt;&lt;br /&gt;&lt;span&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span&gt;3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;4&lt;/span&gt;&lt;br /&gt;&lt;span&gt;5&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2795857313300851433?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2795857313300851433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2795857313300851433&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2795857313300851433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2795857313300851433'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/function-to-get-tabular-data-from.html' title='Function To Get Tabular Data From a Delimilted String Variable'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1871398141164841819</id><published>2009-07-15T11:03:00.003+05:30</published><updated>2009-07-21T18:25:00.922+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Get Values of a Column in a Variable</title><content type='html'>&lt;span style="font-family: arial;"&gt;Get all the values of a single column in a variable separated by comma.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DECLARE a Variable and set the Size of the variable according to your requirement. here in this code i have mentioned MAX.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Now Using :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0); font-family: arial;font-size:85%;" &gt;SELECT  @TempString =  @TempString + CityName +',' FROM Tbl_City&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Statement we can append all the values in @TempString separated by comma.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;@TempString contains a extra comma at the end. so we need to remove that with the help of :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-family: arial; color: rgb(0, 153, 0);font-size:85%;" &gt;SUBSTRING(@TempString,0,LEN(@TempString))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;font-size:100%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;u&gt;Sample Code:&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-style: italic;"&gt;DECLARE @TempString VARCHAR(MAX)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;SET @TempString = ''&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;SELECT  @TempString =  @TempString + CityName +',' FROM Tbl_City&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;SELECT SUBSTRING(@TempString,0,LEN(@TempString))&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1871398141164841819?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1871398141164841819/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1871398141164841819&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1871398141164841819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1871398141164841819'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/get-values-of-column-in-variable.html' title='Get Values of a Column in a Variable'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8836762309419538672</id><published>2009-07-14T18:22:00.003+05:30</published><updated>2009-10-06T15:55:23.446+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Directly Create SQL Update Statements of Data in a Table</title><content type='html'>&lt;span style="font-size: 100%;"&gt;&lt;span style="font-family: arial;"&gt;These Set of statements are used to directly create SQL update statements of data for given table.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;we just need to pass the name of the Table. Here in this just replace &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-size: 100%; font-weight: bold;"&gt;'MyTestTable'&lt;/span&gt;&lt;span style="font-size: 100%;"&gt;&lt;span style="font-family: arial;"&gt; with your own table name.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if there is any identity Column in your table then that will be used for the where condition otherwise first numeric column will be used for where condition.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900; font-size: 85%; font-style: italic;"&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DECLARE @TempString VARCHAR(7999),@Tablename varchar(200)&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #009900; font-family: arial; font-size: 85%; font-style: italic; font-weight: bold;"&gt;SET @Tablename='MyTestTable'&lt;/span&gt;&lt;span style="font-size: 100%;"&gt;&lt;span style="color: #009900; font-size: 85%; font-style: italic;"&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SET @TempString = ''&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #009900; font-size: 85%;"&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SELECT @TempString =  @TempString + SYS.Columns.Name+'=''''''+ISNULL('+SYS.Columns.Name+','''')+'''''','&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;FROM SYS.Columns  Inner JOIN SYS.Objects  ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SYS.Columns.System_type_id IN (239,175,167,231,99,35,34)AND SYS.Columns.IS_Identity=0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SELECT @TempString =  @TempString + SYS.Columns.Name+'=''''''+CONVERT(varchar(30),ISNULL('+SYS.Columns.Name+',''1/1/1900''))+'''''','&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;FROM SYS.Columns  Inner JOIN SYS.Objects  ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SYS.Columns.System_type_id IN (61)AND SYS.Columns.IS_Identity=0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SELECT  @TempString =  @TempString + SYS.Columns.Name+'=''+CONVERT(varchar(10),ISNULL('+SYS.Columns.Name+',0))+'','&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt; FROM SYS.Columns  Inner JOIN SYS.Objects  ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SYS.Columns.System_type_id NOT IN (239,175,167,231,99,35,34,61)AND SYS.Columns.IS_Identity=0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SET @TempString= SUBSTRING(@TempString,0,LEN(@TempString)-2)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;DECLARE @ConditionColumn varchar(200)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SELECT @ConditionColumn=SYS.Columns.name  FROM SYS.Columns  Inner JOIN SYS.Objects  ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and IS_Identity=1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;IF (@ConditionColumn=NULL)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;    SELECT TOP 1 @ConditionColumn=SYS.Columns.name  FROM SYS.Columns  Inner JOIN SYS.Objects &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;        ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;    WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename AND&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;        SYS.Columns.System_type_id NOT IN (239,175,167,231,99,35,34,61)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SET @ConditionColumn=' +'' WHERE '+@ConditionColumn+'=''+CONVERT(varchar(10),ISNULL('+@ConditionColumn+',0))'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;DECLARE @SQLQuery varchar(Max),@SubQuery varchar(Max)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SET @SubQuery='''UPDATE '+@Tablename+' SET '+@TempString+ &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 100%;"&gt;&lt;span style="color: #009900; font-size: 85%;"&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;ISNULL(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 100%;"&gt;&lt;span style="color: #009900; font-size: 85%;"&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;@ConditionColumn&lt;/span&gt;,'')&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SET @SQLQuery= 'SELECT ' +@SubQuery+' FROM '+@Tablename&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;EXEC (@SQLQuery)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8836762309419538672?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8836762309419538672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8836762309419538672&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8836762309419538672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8836762309419538672'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/directly-create-sql-update-statements.html' title='Directly Create SQL Update Statements of Data in a Table'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-4998785383447643810</id><published>2009-07-14T18:14:00.005+05:30</published><updated>2011-07-21T16:33:19.135+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Directly Create SQL Insert Statements of Data in a Table</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;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div closure_uid_e2v7ur="123"&gt;&lt;div closure_uid_zdapat="109"&gt;&lt;span style="font-family: arial; font-size: 100%;"&gt;This Statements are Used to directly create SQL insert statements of data in a table.&lt;br /&gt;we just need to pass the name of the SQL Table as i passed&lt;br /&gt;Replace &lt;/span&gt;&lt;span style="font-family: arial; font-size: 100%; font-weight: bold;"&gt;'MyTestTable'&lt;/span&gt;&lt;span style="font-family: arial; font-size: 100%;"&gt; with your table name and execute these statement.&lt;/span&gt;&lt;/div&gt;&lt;div closure_uid_zdapat="109"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div closure_uid_zdapat="109"&gt;&lt;span style="font-family: Arial;"&gt;&lt;strong&gt;&lt;u closure_uid_zdapat="121"&gt;Query for SQL Server 2005 and 2008:&lt;/u&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;blockquote&gt;DECLARE @TempString VARCHAR(7999),@Tablename varchar(200),@ColumnName varchar(500)&lt;br /&gt;SET @Tablename='Room_Product'&lt;br /&gt;&lt;div closure_uid_zdapat="120"&gt;SET @TempString = ''&lt;/div&gt;SET @ColumnName='' &lt;br /&gt;&lt;br /&gt;SELECT @TempString = @TempString + '+'''''',''''''+ISNULL('+SYS.Columns.Name+','''')'&lt;br /&gt;FROM SYS.Columns Inner JOIN SYS.Objects ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;br /&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;br /&gt;SYS.Columns.System_type_id IN (239,175,167,231,99,35,34)&lt;br /&gt;&lt;br /&gt;IF(@TempString &amp;lt;&amp;gt;'')&lt;br /&gt;SET @TempString='''''''' + @TempString&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECT @TempString = @TempString + '+'''''',''''''+CONVERT(varchar(30),ISNULL('+SYS.Columns.Name+',0))'&lt;br /&gt;FROM SYS.Columns Inner JOIN SYS.Objects ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;br /&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;br /&gt;SYS.Columns.System_type_id IN (61)&lt;br /&gt;&lt;br /&gt;&lt;div closure_uid_e2v7ur="125"&gt;SET @TempString=@TempString+'+'''''''''&lt;/div&gt;&lt;br /&gt;SELECT @ColumnName = @ColumnName + ','+SYS.Columns.Name&lt;br /&gt;FROM SYS.Columns Inner JOIN SYS.Objects ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;br /&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;br /&gt;SYS.Columns.System_type_id IN (239,175,167,231,99,35,34)&lt;br /&gt;&lt;br /&gt;SELECT @ColumnName = @ColumnName + ','+SYS.Columns.Name&lt;br /&gt;FROM SYS.Columns Inner JOIN SYS.Objects ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;br /&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;br /&gt;SYS.Columns.System_type_id IN (61)&lt;br /&gt;&lt;br /&gt;SELECT @TempString = @TempString + '+'',''+CONVERT(varchar(10),ISNULL('+SYS.Columns.Name+',0))'&lt;br /&gt;FROM SYS.Columns Inner JOIN SYS.Objects ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;br /&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;br /&gt;SYS.Columns.System_type_id NOT IN (239,175,167,231,99,35,34,61)&lt;br /&gt;&lt;br /&gt;SELECT @ColumnName = @ColumnName + ','+SYS.Columns.Name&lt;br /&gt;FROM SYS.Columns Inner JOIN SYS.Objects ON SYS.Objects.Object_Id=SYS.Columns.Object_Id&lt;br /&gt;WHERE SYS.Objects.type='u' and SYS.Objects.name=@Tablename and&lt;br /&gt;SYS.Columns.System_type_id NOT IN (239,175,167,231,99,35,34,61)&lt;br /&gt;&lt;br /&gt;SET @TempString= SUBSTRING(@TempString,9,LEN(@TempString)-8)&lt;br /&gt;SET @ColumnName= SUBSTRING(@ColumnName,2,LEN(@ColumnName)-1)&lt;br /&gt;--SELECT @TempString,@ColumnName&lt;br /&gt;&lt;br /&gt;DECLARE @SubQuery varchar(5000),@SQLQuery varchar(max)&lt;br /&gt;SET @SubQuery='INSERT INTO '+@Tablename+'('+@ColumnName+') VALUES ('+@TempString+'+'''+')'&lt;br /&gt;SET @SQLQuery='SELECT '''+@SubQuery+''' FROM '+@Tablename&lt;br /&gt;&lt;br /&gt;EXEC (@SQLQuery)&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;strong&gt;&lt;u&gt;&lt;span style="font-family: arial; font-size: 100%;"&gt;Query for SQL Server 2000:&lt;/span&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;&lt;blockquote&gt;DECLARE @TempString VARCHAR(7999),@Tablename varchar(200),@ColumnName varchar(500)&lt;br /&gt;SET @Tablename='tblProdline'&lt;br /&gt;SET @TempString = ''&lt;br /&gt;SET @ColumnName='' &lt;br /&gt;&lt;br /&gt;SELECT @TempString = @TempString + '+'''''',''''''+ISNULL('+SYSColumns.Name+','''')'&lt;br /&gt;FROM SYSColumns Inner JOIN SYSObjects ON SYSObjects.ID=SYSColumns.ID&lt;br /&gt;WHERE SYSObjects.type='u' and SYSObjects.name=@Tablename and&lt;br /&gt;SYSColumns.xtype IN (239,175,167,231,99,35,34)&lt;br /&gt;&lt;br /&gt;IF(@TempString &amp;lt;&amp;gt;'')&lt;br /&gt;SET @TempString='''''''' + @TempString&lt;br /&gt;&lt;br /&gt;SELECT @TempString = @TempString + '+'''''',''''''+CONVERT(varchar(30),ISNULL('+SYSColumns.Name+',0))'&lt;br /&gt;FROM SYSColumns Inner JOIN SYSObjects ON SYSObjects.ID=SYSColumns.ID&lt;br /&gt;WHERE SYSObjects.type='u' and SYSObjects.name=@Tablename and&lt;br /&gt;SYSColumns.xtype IN (61)&lt;br /&gt;&lt;br /&gt;SET @TempString=@TempString+'+'''''''''&lt;br /&gt;&lt;br /&gt;SELECT @ColumnName = @ColumnName + ','+SYSColumns.Name&lt;br /&gt;FROM SYSColumns Inner JOIN SYSObjects ON SYSObjects.ID=SYSColumns.ID&lt;br /&gt;WHERE SYSObjects.type='u' and SYSObjects.name=@Tablename and&lt;br /&gt;SYSColumns.xtype IN (239,175,167,231,99,35,34)&lt;br /&gt;&lt;br /&gt;SELECT @ColumnName = @ColumnName + ','+SYSColumns.Name&lt;br /&gt;FROM SYSColumns Inner JOIN SYSObjects ON SYSObjects.ID=SYSColumns.ID&lt;br /&gt;WHERE SYSObjects.type='u' and SYSObjects.name=@Tablename and&lt;br /&gt;SYSColumns.xtype IN (61)&lt;br /&gt;&lt;br /&gt;SELECT @TempString = @TempString + '+'',''+CONVERT(varchar(10),ISNULL('+SYSColumns.Name+',0))'&lt;br /&gt;FROM SYSColumns Inner JOIN SYSObjects ON SYSObjects.ID=SYSColumns.ID&lt;br /&gt;WHERE SYSObjects.type='u' and SYSObjects.name=@Tablename and&lt;br /&gt;SYSColumns.xtype NOT IN (239,175,167,231,99,35,34,61)&lt;br /&gt;&lt;br /&gt;SELECT @ColumnName = @ColumnName + ','+SYSColumns.Name&lt;br /&gt;FROM SYSColumns Inner JOIN SYSObjects ON SYSObjects.ID=SYSColumns.ID&lt;br /&gt;WHERE SYSObjects.type='u' and SYSObjects.name=@Tablename and&lt;br /&gt;SYSColumns.xtype NOT IN (239,175,167,231,99,35,34,61)&lt;br /&gt;&lt;br /&gt;SET @TempString= SUBSTRING(@TempString,9,LEN(@TempString)-8)&lt;br /&gt;SET @ColumnName= SUBSTRING(@ColumnName,2,LEN(@ColumnName)-1)&lt;br /&gt;--SELECT @TempString,@ColumnName&lt;br /&gt;&lt;br /&gt;DECLARE @SubQuery varchar(5000),@SQLQuery varchar(8000)&lt;br /&gt;SET @SubQuery='INSERT INTO '+@Tablename+'('+@ColumnName+') VALUES ('+@TempString+'+'''+')'&lt;br /&gt;SET @SQLQuery='SELECT '''+@SubQuery+''' FROM '+@Tablename&lt;br /&gt;&lt;br /&gt;EXEC (@SQLQuery)&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-4998785383447643810?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/4998785383447643810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=4998785383447643810&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4998785383447643810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4998785383447643810'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/directly-create-sql-insert-statements.html' title='Directly Create SQL Insert Statements of Data in a Table'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8725967949012990610</id><published>2009-07-04T14:04:00.006+05:30</published><updated>2009-07-21T18:32:30.465+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Update Table Query to update data from another table directly</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Suppose we have two tables names:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Tbl_Topics  &amp;amp;  Tbl_TeacherTopics  having columns&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;MyTopic, TopicId, TopicName&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;TeacherTopicID, TopicId, TopicName&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;And we want to update Tbl_Topics Table from Tbl_TeacherTopics for given TeacherTopicID&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;&lt;u&gt;Query&lt;/u&gt;:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;&lt;span style=""&gt;UPDATE Tbl_Topics SET TopicID=TT.TopicID,TopicName=TT.TopicName FROM&lt;/span&gt;&lt;br /&gt;&lt;span style=""&gt;(SELECT TopicID,TopicName FROM Tbl_TeacherTopics WHERE TeacherTopicID=1062)AS TT&lt;/span&gt;&lt;br /&gt;&lt;span style=""&gt;WHERE Tbl_Topics.MyTopic='Lakhan Pal garg'&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8725967949012990610?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8725967949012990610/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8725967949012990610&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8725967949012990610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8725967949012990610'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/07/update-table-query-to-update-data-from.html' title='Update Table Query to update data from another table directly'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-1695211354118584056</id><published>2009-06-22T17:39:00.003+05:30</published><updated>2009-07-21T18:34:55.298+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Save Image For given URL</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Set Url of the Image you want to save on your system.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;DestinationPath is the path where you want to save the image.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt; in this case it is Products folder on the root of the application folder.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;strImage = url.Substring(url.LastIndexOf('/') + 1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;above line of code will give us the name of the image.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;GetBytesFromUrl(url); method will return the Byte array of the image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;for the corrsponding url of the image.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Once we got the Byte image data in the form of Byte array then&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;we can save the image using WriteBytesToFile method.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;string url = "http://3.bp.blogspot.com/_Kp--fzJWFmc/&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;strImage = url.Substring(url.LastIndexOf('/') + 1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;string DestinationPath = Server.MapPath("~/Products");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;byte[] bytes = GetBytesFromUrl(url);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;WriteBytesToFile(DestinationPath + "/" + strImage, bytes);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;First we make the request for the given image url and server&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;will send us a response for that request in the form of stream of data.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;With the help of BinaryReader system will read the content of image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;and add that into byte array.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;static public byte[] GetBytesFromUrl(string url)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        byte[] b;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        HttpWebRequest myReq =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;       (HttpWebRequest)WebRequest.Create(url);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        WebResponse myResp = myReq.GetResponse();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        Stream stream = myResp.GetResponseStream();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        //int i;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        using (BinaryReader br = new BinaryReader(stream))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;            //i = (int)(stream.Length);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;            b = br.ReadBytes(500000);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;            br.Close();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        myResp.Close();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;        return b;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Here we'll write the Byte array data with the help of&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;BinaryWriter on the given destinaion path.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;static public void WriteBytesToFile(string fileName, byte[] content)&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;    {&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;        FileStream fs = new FileStream(fileName, FileMode.Create);&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;        BinaryWriter w = new BinaryWriter(fs);&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;        try&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;        {&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;            w.Write(content);&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;        }&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;        finally&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;        {&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;            fs.Close();&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;            w.Close();&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;        }&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;    }&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-1695211354118584056?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/1695211354118584056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=1695211354118584056&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1695211354118584056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/1695211354118584056'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/06/save-image-for-given-url.html' title='Save Image For given URL'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-4550505531644539721</id><published>2009-06-22T17:33:00.002+05:30</published><updated>2009-07-21T18:36:50.867+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Import/Export CSV'/><title type='text'>Import Data to CSV File FROM DataTable</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;In th First step we will Clear the Response Object and then we'll attach a csv file with the Response Object. that will be popup once we'll write the Data into it and End the Response Object.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;After Attaching the file we'll write the column Name into the CSV File. and then iterate for all the Records to write them into the CSV file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;"" is used to protect the Data if the data contain ',' (Comma) .&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;&lt;u&gt;Sample Code&lt;/u&gt;:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;DataTable dtProducts=GetProductsFromDB();&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;string attachment = "attachment; filename=products.csv";&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;HttpContext.Current.Response.Clear();&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;HttpContext.Current.Response.ClearHeaders();&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;HttpContext.Current.Response.ClearContent();&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;HttpContext.Current.Response.AddHeader("content-disposition", attachment);&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;HttpContext.Current.Response.ContentType = "application/octet-stream";&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;//Write Column Names&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;string str = "ProductNo,Product,SKU,ProductType,Price";&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;HttpContext.Current.Response.Write(str);&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;HttpContext.Current.Response.Write(Environment.NewLine);&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;for(int i =0; i&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;{&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt; string strRowData="";&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;  for(int jColumns=0; jColumns&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;  {&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;   if(strRowData=="")&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;     strRowData='"'+dtProducts.Rows[i][jColumns].ToString()+'"';&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;    else&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;     {&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;          strRowData=","+'"'+dtProducts.Rows[i][jColumns].ToString()+'"';&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;     }&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;  }&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;       HttpContext.Current.Response.Write(strRowData);&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;       HttpContext.Current.Response.Write(Environment.NewLine);&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;       strRowData="";&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;}&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;HttpContext.Current.Response.End();&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-4550505531644539721?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/4550505531644539721/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=4550505531644539721&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4550505531644539721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4550505531644539721'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/06/import-data-to-csv-file-from-datatable.html' title='Import Data to CSV File FROM DataTable'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-683967222420800645</id><published>2009-05-23T14:41:00.005+05:30</published><updated>2009-07-21T18:38:19.041+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Scaling height width of the object.</title><content type='html'>&lt;span style="font-family: arial;"&gt;In This Sample you need maximum width of the object&lt;/span&gt; &lt;span style="font-family: arial;"&gt;1024 and maximum height 750; You need to pass the width &lt;/span&gt;&lt;span style="font-family: arial;"&gt;and height of object (dblWidth  AND dblHeight) and you will&lt;/span&gt; &lt;span style="font-family: arial;"&gt;get the scaled height and width of the object.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;Double dblWRatio =0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;//Actual Width of the Object&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Double dblWidth =1280;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;//Actual Height of the Object&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Double dblHeight =960&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;//Maximum width of the Object&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Double PalyerWidth =1024;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;//Maximum height of the Object&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Double PlayerHeight =750;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;dblWRatio = ((PalyerWidth - dblWidth) * 100) / dblWidth;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;dblWidth += dblWidth * (dblWRatio / 100);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;dblHeight += dblHeight * (dblWRatio / 100);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (dblHeight &gt; PlayerHeight)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      dblHRatio = ((PlayerHeight - dblHeight) * 100) / dblHeight;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      dblWidth += dblWidth * (dblHRatio / 100);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      dblHeight += dblHeight * (dblHRatio / 100);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-683967222420800645?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/683967222420800645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=683967222420800645&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/683967222420800645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/683967222420800645'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/05/scaling-height-width-of-object.html' title='Scaling height width of the object.'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8073563823891067981</id><published>2009-05-23T14:31:00.006+05:30</published><updated>2009-07-21T18:40:14.420+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>string v/s StringBuilder</title><content type='html'>&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;System.Text.StringBuilder strTest=new System.Text.StringBuilder();&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Strings are immutable. immutable means every time we alter&lt;/span&gt; &lt;span style="font-family:arial;"&gt;the string a new object is created. hence lower the performance. &lt;/span&gt;&lt;span style="font-family:arial;"&gt;while stringBuilder are mutable. so it increase the performance&lt;/span&gt; &lt;span style="font-family:arial;"&gt;where we need to perform altered, insert and remove operations. &lt;/span&gt;&lt;span style="font-family:arial;"&gt;But it is not recommended to use StringBuilder always. for small &lt;/span&gt;&lt;span style="font-family:arial;"&gt;string where you need to perform less operation then use string&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;and in case of large string and more operation use StringBuilder.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8073563823891067981?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8073563823891067981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8073563823891067981&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8073563823891067981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8073563823891067981'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/05/string-vs-stringbuilder.html' title='string v/s StringBuilder'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-607743131372916459</id><published>2009-05-23T14:22:00.007+05:30</published><updated>2009-07-21T18:47:19.224+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Import/Export CSV'/><title type='text'>Read the CSV Data and Save the Data in DataSet.</title><content type='html'>&lt;pre  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;In this first we will read the data from csv file using the select query and load the data into a dataset.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Query To read data from CSV file&lt;span style="font-weight: bold;"&gt;: &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:100%;" &gt;SELECT * FROM [test.csv]&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;OLEDB Connectionstring:&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-size:100%;" &gt;&lt;span style="font-style: italic;"&gt; @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Lakhan\Projects\Testweb\Test\;Extended&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Properties=""text;HDR=Yes;FMT=Delimited"""&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;if you want to consider first row as column then mention HDR=Yes otherwise no.&lt;br /&gt;using System.Data.OleDb;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-size:100%;" &gt;&lt;span style="font-style: italic;"&gt;for(Int32 i=0; i&lt;/span&gt;&lt;/span&gt;&lt;datasetfromcsv.tables[0].columns.count;&gt;&lt;span style="color: rgb(0, 153, 0);font-size:100%;" &gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;   {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;       Response.Write(dataSetFromCSV.Tables[0].Columns[i].&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;       ColumnName + "");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;   }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;the above code is used to print all the column names&lt;/datasetfromcsv.tables[0].columns.count;&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;u&gt;Sample Code&lt;/u&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:100%;" &gt;using System.Data.OleDb;&lt;br /&gt;private void ReadCSVFile()&lt;br /&gt;{&lt;br /&gt; string cnStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data&lt;br /&gt; Source=E:\Lakhan\Projects\Testweb\Test\;Extended&lt;br /&gt; Properties=""text;HDR=Yes;FMT=Delimited""";&lt;br /&gt; OleDbConnection ExcelConnection =&lt;br /&gt; new OleDbConnection(cnStr);&lt;br /&gt; OleDbCommand ExcelCommand = new OleDbCommand&lt;br /&gt; (@"SELECT * FROM [test.csv]",&lt;br /&gt; ExcelConnection);&lt;br /&gt; OleDbDataAdapter ExcelAdapter =&lt;br /&gt; new OleDbDataAdapter(ExcelCommand);&lt;br /&gt; ExcelConnection.Open();&lt;br /&gt;      &lt;br /&gt; DataSet dataSetFromCSV = new DataSet();&lt;br /&gt; ExcelAdapter.Fill(dataSetFromCSV);&lt;br /&gt; ExcelConnection.Close();&lt;br /&gt; for(Int32 i=0; i&lt;/span&gt;&lt;datasetfromcsv.tables[0].columns.count;&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:100%;" &gt;&lt;br /&gt; {&lt;br /&gt;     Response.Write(dataSetFromCSV.Tables[0].&lt;br /&gt;     Columns[i].ColumnName + "");&lt;br /&gt; }&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/datasetfromcsv.tables[0].columns.count;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;CSV File's Content:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;Customer Number,Last Name,First Name,Address,City,Province,&lt;br /&gt;Postal Code,Balance10001,Smith,Dave,123 Parkside Ave.,London,&lt;br /&gt;ON,N6J 4G6,125.3510002,Pearson,Anne,44 Northside Road,Toronto,&lt;br /&gt;ON,N0M 5L8,38.1210003,Carson,Ronald,12 Talbot Road,London,&lt;br /&gt;ON,N6U 3G8,1024.5610006,Davis,Albert,19 Southam Road,Ajax,&lt;br /&gt;ON,N7J 5H7,-8.5510007,Anderson,Theresa,118 Sarnia Road,&lt;br /&gt;London,ON,N6G 5C6,1181.1210009,Jones,Jason,1008,&lt;br /&gt;Carver Place,Ottawa,ON,N8K 8H4,0.00&lt;/span&gt;&lt;span id="ctl00_ContentPlaceHolder1_lblDescription" style=";font-size:100%;color:DarkBlue;"  &gt;&lt;datasetfromcsv.tables[0].columns.count;&gt;&lt;/datasetfromcsv.tables[0].columns.count;&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-607743131372916459?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/607743131372916459/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=607743131372916459&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/607743131372916459'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/607743131372916459'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/05/read-csv-data-and-save-data-in-dataset.html' title='Read the CSV Data and Save the Data in DataSet.'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-7783656464589755644</id><published>2009-05-15T17:48:00.008+05:30</published><updated>2009-09-14T13:26:29.469+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>XSLT (Extensible StyleSheet Language Transformations)</title><content type='html'>XSL stands for Extensible StyleSheet Language, and is a style sheet language for XML documents. XSLT stands for XSL Transformations. XSL = Style Sheets for XML.XSL consists of three parts:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;XSLT - a language for transforming XML documents&lt;/li&gt;&lt;li&gt;XPath - a language for navigating in XML documents&lt;/li&gt;&lt;li&gt;XSL-FO - a language for formatting XML documents&lt;/li&gt;&lt;/ul&gt;XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XPath is a language for navigating in XML documents.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Example:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;Implement Style on xml data:&lt;br /&gt;*********************** Sample: Sample1.xml ************************&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="ISO-8859-1" ?&amp;gt;&lt;br /&gt;&amp;lt;?xml-stylesheet type="text/xsl" href="Sample1.xslt"?&amp;gt;&lt;br /&gt;&amp;lt;SqlData&amp;gt;&lt;br /&gt;&amp;lt;Table&amp;gt;&lt;br /&gt;&amp;lt;UserName&amp;gt;lakhangarg@gmail.com&amp;lt;/UserName&amp;gt;&lt;br /&gt;&amp;lt;FirstName&amp;gt;Lakhan Pal Garg&amp;lt;/FirstName&amp;gt;&lt;br /&gt;&amp;lt;Blog&amp;gt;http://www.lakhangarg.blogspot.com&amp;lt;/Blog&amp;gt;&lt;br /&gt;&amp;lt;/Table&amp;gt;&lt;br /&gt;&amp;lt;/SqlData&amp;gt;&lt;br /&gt;&lt;br /&gt;********************* XSLT Sample: Sample1.xslt ************************&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="ISO-8859-1" ?&amp;gt;&lt;br /&gt;&amp;lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&amp;gt;&lt;br /&gt;&amp;lt;xsl:template match="/"&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;b&amp;gt;Author: &amp;lt;/b&amp;gt;&amp;lt;xsl:value-of select="SqlData/Table/FirstName" /&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b&amp;gt;Email ID:&amp;lt;/b&amp;gt;&amp;lt;xsl:value-of select="SqlData/Table/UserName" /&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b&amp;gt;Blog:&amp;lt;/b&amp;gt;&amp;lt;xsl:value-of select="SqlData/Table/Blog" /&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;******************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Code to implement stylesheet on xml document:&lt;/u&gt;&lt;br /&gt;  XmlDocument docXML = new XmlDocument();&lt;br /&gt;  XslTransform docXSL = new XslTransform();&lt;br /&gt;  docXML.Load(Server.MapPath("sample1.xml"));&lt;br /&gt;  docXSL.Load(Server.MapPath("sample1.xslt"));&lt;br /&gt;  Xml1.Document = docXML;&lt;br /&gt;  Xml1.Transform = docXSL;&lt;br /&gt;******************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Output:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;div&gt;&lt;b&gt;Author: &lt;/b&gt;Lakhan Pal Garg&lt;br /&gt;&lt;b&gt;Email  ID:&lt;/b&gt;lakhangarg@gmail.com&lt;br /&gt;&lt;b&gt;Blog:&lt;/b&gt;http://www.lakhangarg.blogspot.com  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-7783656464589755644?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/7783656464589755644/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=7783656464589755644&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7783656464589755644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7783656464589755644'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/05/xslt-definition.html' title='XSLT (Extensible StyleSheet Language Transformations)'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-446054877411679171</id><published>2009-05-15T17:36:00.007+05:30</published><updated>2009-09-08T18:18:53.562+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>Language Integrated Query (LINQ)</title><content type='html'>LINQ Stands for Language-Integrated Query. LINQ has a great power of querying on any source of data, data source could be the collections of objects, database or XML files. We can easily retrieve data from any object that implements the IEnumerable&lt;t&gt; interface. Microsoft basically divides LINQ into three areas and that are give below:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;LINQ to Object {Queries performed against the in-memory data}&lt;br /&gt;&lt;/li&gt;&lt;li&gt;LINQ to ADO.Net&lt;ul&gt;&lt;li&gt;LINQ to SQL (formerly DLinq) {Queries performed against the relation database only  Microsoft SQL Server Supported}&lt;/li&gt;&lt;li&gt;LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables}&lt;br /&gt;&lt;/li&gt;&lt;li&gt;LINQ to Entities {Microsoft ORM solution}&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;LINQ to XML (formerly XLinq) { Queries performed against the XML source}&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;&lt;u&gt;Example:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;/t&gt;int[] nums={0,1,2,3,4,5};&lt;br /&gt;&lt;t&gt;var res = from a in nums&lt;br /&gt;         where a &amp;lt; 3&lt;br /&gt;         orderby a&lt;br /&gt;         select a;&lt;br /&gt;foreach(int i in res)&lt;br /&gt;Console.WriteLine(i);&lt;br /&gt;Output:&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;&lt;/t&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-446054877411679171?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/446054877411679171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=446054877411679171&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/446054877411679171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/446054877411679171'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/05/linq-language-integrated-query.html' title='Language Integrated Query (LINQ)'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8158945917966328275</id><published>2009-05-15T17:26:00.003+05:30</published><updated>2009-06-23T10:48:46.803+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>ref v/s out Parametes in C#</title><content type='html'>out and ref looks quite similar in nature.Both parameters are used to return back some value to the caller of the function. But still there is a important difference between them. these two types are used for specific purpose.&lt;br /&gt;When we use the out parameter, The program calling the function need not assign a value to the out parameter before making the call to the function. The value of the out parameter has to be set by the function before returning the value.&lt;br /&gt;For a ref type parameter, the value to the parameter has to be assigned before calling the function. If we do not assign the value before calling the function we will get a compiler error.&lt;br /&gt;Another important thing to note here is that in case of ref parameter, the value passed by the caller function can be very well used by the called function. The called function does not have the compulsion to assign the value to a ref type parameter. But in case of the out parameter, the called function has to assign a value.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8158945917966328275?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8158945917966328275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8158945917966328275&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8158945917966328275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8158945917966328275'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/05/ref-vs-out-parametes.html' title='ref v/s out Parametes in C#'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8775192427332833811</id><published>2009-05-13T16:27:00.008+05:30</published><updated>2009-07-22T10:10:09.816+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Cross Tab Query-SQL Server</title><content type='html'>&lt;div style="text-align: center; font-weight: bold; font-family: arial;"&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-weight: normal;"&gt;Query is used to convert  column into rows using the cross tab query.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;DECLARE @select varchar(8000),@sumfunc varchar(100),@pivot varchar(100)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DECLARE @table varchar(100)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SET @select='SELECT CustID,SalesID FROM testTable GROUP BY CustID,SalesID'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SET @sumfunc='SUM(adsID)'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SET @pivot='adsID'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SET @table='testTable'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DECLARE @sql varchar(8000), @delim varchar(1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SET NOCOUNT ON&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SET ANSI_WARNINGS OFF&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;EXEC ('SELECT ' + @pivot + ' AS pivot1 INTO ##pivot FROM ' + @table + ' WHERE 1=2')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;EXEC ('INSERT INTO ##pivot SELECT DISTINCT ' + @pivot + ' FROM ' + @table + ' WHERE '&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;+ @pivot + ' Is Not Null')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELECT @sql='',  @sumfunc=stuff(@sumfunc, len(@sumfunc), 1, ' END)' )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;print @sql&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELECT @delim=CASE Sign( CharIndex('char', data_type)+CharIndex('date', data_type) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;WHEN 0 THEN '' ELSE '''' END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;FROM tempdb.information_schema.columns&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;WHERE table_name='##pivot' AND column_name='pivot1'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELECT @sql=@sql + '''' + convert(varchar(100), pivot1) + ''' = ' +&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;stuff(@sumfunc,charindex( '(', @sumfunc )+1, 0, ' CASE ' + @pivot + ' WHEN '&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;+ @delim + convert(varchar(100), pivot1) + @delim + ' THEN ' ) + ', ' FROM ##pivot&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DROP TABLE ##pivot&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELECT @sql=left(@sql, len(@sql)-1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELECT @select=stuff(@select, charindex(' FROM ', @select)+1, 0, ', ' + @sql + ' ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;EXEC (@select)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SET ANSI_WARNINGS ON&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8775192427332833811?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8775192427332833811/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8775192427332833811&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8775192427332833811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8775192427332833811'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/05/cross-tab-query-sql-server.html' title='Cross Tab Query-SQL Server'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-9076854896209263200</id><published>2009-05-01T15:35:00.006+05:30</published><updated>2009-07-22T10:20:32.472+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Upload file on other system in the network</title><content type='html'>&lt;span style="font-family: arial;"&gt;This Code snippet will help us to upload file on any system other than application server.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Suppose we have separate file and application server then this code will help us to upload image on file server from application server.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Following Namespaces needs to add to upload file:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;using System.Security.Principal;&lt;br /&gt;using System.Runtime.InteropServices;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Summary description for FileHandler&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0); font-family: arial;font-size:85%;" &gt;public class FileHandler&lt;br /&gt;{&lt;br /&gt; public const int LOGON32_LOGON_INTERACTIVE = 2;&lt;br /&gt; public const int LOGON32_PROVIDER_DEFAULT = 0;&lt;br /&gt;&lt;br /&gt; WindowsImpersonationContext impersonationContext;&lt;br /&gt;&lt;br /&gt; //Programatically Add Service to Get Token&lt;br /&gt; [DllImport("advapi32.dll")]&lt;br /&gt; public static extern int LogonUserA(String lpszUserName,&lt;br /&gt;     String lpszDomain,&lt;br /&gt;     String lpszPassword,&lt;br /&gt;     int dwLogonType,&lt;br /&gt;     int dwLogonProvider,&lt;br /&gt;     ref IntPtr phToken);&lt;br /&gt; [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;&lt;br /&gt; //Programatically Add Service to Check for Duplicate Token&lt;br /&gt; public static extern int DuplicateToken(IntPtr hToken,&lt;br /&gt;     int impersonationLevel,&lt;br /&gt;     ref IntPtr hNewToken);&lt;br /&gt;&lt;br /&gt; //RevertToSelf terminates the impersonation of a client application.&lt;br /&gt; [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt; public static extern bool RevertToSelf();&lt;br /&gt;&lt;br /&gt; //Programatically Add Service to Terminate Process&lt;br /&gt; [DllImport("kernel32.dll", CharSet = CharSet.Auto)]&lt;br /&gt; public static extern bool CloseHandle(IntPtr handle);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This method is used to get the token privilege for a valid user&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;public bool impersonateValidUser()&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      WindowsIdentity tempWindowsIdentity;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      IntPtr token = IntPtr.Zero;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      IntPtr tokenDuplicate = IntPtr.Zero;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      if (RevertToSelf())&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;          if (LogonUserA(ConfigurationManager.AppSettings["DomainUser"].ToString(), ConfigurationManager.AppSettings["Domain"].ToString(), ConfigurationManager.AppSettings["DomainPassword"].ToString(), LOGON32_LOGON_INTERACTIVE,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;              LOGON32_PROVIDER_DEFAULT, ref token) != 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;          {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;              if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;              {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  impersonationContext = tempWindowsIdentity.Impersonate();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  if (impersonationContext != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                      CloseHandle(token);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                      CloseHandle(tokenDuplicate);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                      return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;              }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;          }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      if (token != IntPtr.Zero)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;          CloseHandle(token);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      if (tokenDuplicate != IntPtr.Zero)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;          CloseHandle(tokenDuplicate);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      return false;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Method to Upload file on network path. parameter of this functions are:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;fileuploadcontrol as reference type, Destination Path as string.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;impersonateValidUser() method is used to get the token for a valid user.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;once we got the token we can save image on other system.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;public Boolean  UploadFile(ref FileUpload flUpload,string NetworkPath)&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      if (impersonateValidUser())&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;          flUpload.SaveAs(NetworkPath + flUpload.FileName);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;          return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;          return false;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-9076854896209263200?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/9076854896209263200/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=9076854896209263200&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/9076854896209263200'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/9076854896209263200'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/05/upload-file-on-other-system-in-network.html' title='Upload file on other system in the network'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-8028245970657309264</id><published>2009-04-30T21:59:00.005+05:30</published><updated>2009-07-22T10:23:49.081+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Javascript-  Pop Up window Using the window.open method</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;"&gt;The syntax of the window.open method is given below:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:100%;" &gt;window.open (URL, windowName, Features)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:100%;" &gt;URL&lt;/span&gt;&lt;span style="font-size:100%;"&gt;:&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The URL of the page to open in the new window. This argument could be blank.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:100%;" &gt;Window Name&lt;/span&gt;&lt;span style="font-size:100%;"&gt;:&lt;br /&gt;&lt;span style="font-family: arial;"&gt;A name to be given to the new window. The name can be used to&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;refer this window again.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:100%;" &gt;Features&lt;/span&gt;&lt;span style="font-size:100%;"&gt;:&lt;br /&gt;&lt;span style="font-family: arial;"&gt;A string that determines the various window features to be included&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;in the pop up window (like status bar, address bar etc)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Code to opens a new browser window with standard features.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial; color: rgb(0, 153, 0); font-style: italic;font-size:100%;" &gt;window.open ("http://www.google.com","mywindow");&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Following are the features of window.open method:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;status:       status bar at the bottom of the window.(e.g: status=1 or 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;toolbar:     The standard browser toolbar, with buttons such as&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Back and Forward. (e.g: toolbar=1 or 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;location:     The Location entry field where you enter the URL.(e.g: location=1 or 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;menubar:    The menu bar of the window (e.g: menubar=1 or 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;resizable:     Allow/Disallow the user to resize the window.(e.g: resizable=1 or 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;scrollbars:    Enable the scrollbars if the document is bigger than the&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;window(e.g: scrollbars=1 or 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;height:          Specifies the height of the window in pixels. (e.g: height='200')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;width:           Specifies the width of the window in pixels. (e.g: width='200')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:100%;" &gt;Example:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The following code opens a window with menu bar and toolbar.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The window is resizable and is having 350 pixels width and 250 pixels height.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:100%;" &gt;window.open ("http://www.google.com ",&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:100%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:100%;" &gt;"mywindow","menubar=1,resizable=1,toolbar=1,&lt;br /&gt;width=350,height=250");&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-8028245970657309264?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/8028245970657309264/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=8028245970657309264&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8028245970657309264'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/8028245970657309264'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/javascript-pop-up-window-using.html' title='Javascript-  Pop Up window Using the window.open method'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2683833535773017943</id><published>2009-04-30T15:11:00.011+05:30</published><updated>2009-07-22T10:25:17.520+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>SQL Server - Reading XML Data</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;DECLARE @XmlHandle int&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DECLARE @XMLDATA nTEXT&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;EXEC sp_xml_preparedocument @XmlHandle output,@XMLDATA&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELECT * FROM OPENXML (@XmlHandle, '{XPath}',{flag})&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;WITH ([col1] int '@xmlAttribute',[col2] VARCHAR(100) '.XMlLElement')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;EXEC sp_xml_removedocument @XmlHandle&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;sp_xml_preparedocument&lt;/span&gt; - Reads the XML text provided as input (@XMLDATA) ,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;the xml text and returns a handle that can be used to access the newly created internal representation of the XML document. The output of this procedure is XML handle that is&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;used for OPENXML command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;sp_xml_removedocument &lt;/span&gt;- A parsed document is stored in the internal cache of&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SQL Server, so sp_xml_removedocument is used to remove the xml document.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;OPENXML&lt;/span&gt;- OPENXML provides a rowset view over an XML document. Because&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;OPENXML is a rowset provider, OPENXML can be used in Transact-SQL&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;statements in which rowset providers such as a table, view, or the&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;OPENROWSET function can appear.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The last Attribute is for flag means weather it is attribute centric, element&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;centric etc. for more details about this&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Visit: http://msdn.microsoft.com/en-us/library/ms186918.aspx&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;***********************************************************************&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial; font-style: italic;"&gt;DECLARE @xmlDoc VARCHAR(8000)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;DECLARE @xmlHandle INT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SET @xmlDoc ='{Products}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;              {Product ID="1"}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;                  {Name}Sugar{/Name}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;                  {Price}30 rs/Kg{/Price}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;              {/Product}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;              {Product ID="2"}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;                  {Name}Milk{/Name}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;                  {Price}22 rs/Kg{/Price}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;              {/Product}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;          {/Products}'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;EXEC sp_xml_preparedocument @xmlHandle OUTPUT, @xmlDoc&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;SELECT * FROM OPENXML (@xmlHandle, '//Product', 2) WITH&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;  (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;      ID        INT            '@ID',&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;      [Name]    VARCHAR(20) 'Name',&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;      Price    VARCHAR(10) 'Price'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;  )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;EXEC sp_xml_removedocument @xmlHandle&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;END&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:100%;" &gt;Output:&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:100%;" &gt;ID    Name    Price&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;1    Sugar    30 rs/Kg&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;2    Milk    22 rs/&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2683833535773017943?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2683833535773017943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2683833535773017943&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2683833535773017943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2683833535773017943'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/sql-server-reading-xml-data.html' title='SQL Server - Reading XML Data'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-7088261198334130793</id><published>2009-04-29T15:12:00.002+05:30</published><updated>2009-07-22T10:32:25.291+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Excel Sheet Import/Export'/><title type='text'>Save Data into Sql Server from Excel sheet</title><content type='html'>Data into SQL Server from Excel sheet (C#). First we will get the data from excel sheet using the select query and OLEDB as provider.&lt;br /&gt;Connection string for OLEDB is:&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;string file = "D:\\Amt.xls";&lt;br /&gt;string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +&lt;br /&gt;file + ";Extended Properties=Excel 8.0;";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Query to fetch data from a excel sheet:&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;string query = "Select Name,Salary from [Sheet1$]";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This Code will help to fetch the data from excel sheet and save the same into dataset.&lt;br /&gt;DataSet dataSet = new DataSet();&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-style: italic;"&gt;using (OleDbConnection Connection = new OleDbConnection(constr))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;using (OleDbDataAdapter DataAdapter =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;new OleDbDataAdapter(query, Connection))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DataAdapter.Fill(dataSet, "Amt1");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DataAdapter.AcceptChangesDuringFill = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Following lines of code will help us to save the data into SQL server DB that we get from excel sheet.&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;constr = "server=B0001;database=master;uid=sa;pwd=sa";&lt;br /&gt;query = "Select Name,Salary from Amt";&lt;br /&gt;using (SqlConnection Connection = new SqlConnection(constr))&lt;br /&gt;{&lt;br /&gt;using (SqlCommand Command = new SqlCommand(query, Connection))&lt;br /&gt;{&lt;br /&gt;using (SqlDataAdapter DataAdapter = new SqlDataAdapter(Command))&lt;br /&gt;{&lt;br /&gt;using (SqlCommandBuilder CommandBuilder =&lt;br /&gt;new SqlCommandBuilder(DataAdapter))&lt;br /&gt;{&lt;br /&gt;Connection.Open();&lt;br /&gt;SqlTransaction Transaction = Connection.BeginTransaction();&lt;br /&gt;Command.Transaction = Transaction;&lt;br /&gt;DataAdapter.InsertCommand = CommandBuilder.GetInsertCommand();&lt;br /&gt;dataSet.AcceptChanges();&lt;br /&gt;int check = DataAdapter.Update(dataSet, "Amt1");&lt;br /&gt;Transaction.Commit();&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-7088261198334130793?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/7088261198334130793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=7088261198334130793&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7088261198334130793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7088261198334130793'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/save-data-into-sql-server-from-excel.html' title='Save Data into Sql Server from Excel sheet'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-4158083787334500423</id><published>2009-04-29T12:56:00.002+05:30</published><updated>2009-07-22T10:46:57.526+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Excel Sheet Import/Export'/><title type='text'>Export Data from Dataset or Datatable to Excel File</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;"&gt;Save Data from DataSet or DataTable to Excel File (VB.NET)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Namespace that needs to import for excel:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;Imports Microsoft.Office.Interop.Excel&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Add instance of excel application&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;Excel = New Excel.Application&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Excel.SheetsInNewWorkbook=3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Add Workbook to the Worksheet&lt;/span&gt;&lt;span style="font-family: arial;"&gt; (We can Add More Workbooks Too in Similar Way)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;Excel.Workbooks.Add()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create new worksheet&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;createWorksheet("Workbook Name")&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Show Dialog Box&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;Dim dlgsave As New SaveFileDialog&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;dlgsave.Filter = "Excel Spreadsheets (*.xls)|*.xls"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If dlgsave.ShowDialog() = DialogResult.OK Then&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;Insert Column Name&lt;/span&gt; into the excel sheet&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;For iDColumn = 0 To dtShareholders.Columns.Count - 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Excel.Cells(iRRow, iRColumn).Value = dtShareholders.&amp;amp;_&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Columns(iDColumn + 1).ColumnName.ToString&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;Excel.Cells(iRRow, iRColumn).Borders.Weight = 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  Excel.Cells(iRRow, iRColumn).Interior.ColorIndex = 49&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  Excel.Cells(iRRow, iRColumn).Font.ColorIndex = 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  Excel.Cells(iRRow, iRColumn).Font.Bold = True&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  Excel.Cells(iRRow, iRColumn).FormulaHidden = True&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  Excel.Cells(iRRow, iRColumn).RowHeight = 25&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  Excel.Cells(iRRow, iRColumn).VerticalAlignment = xlCenter&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  iRColumn = iRColumn + 1&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;Next&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;"&gt;This loop will print all rows one by one into the excel sheet&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;iRRow = iRRow + 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;For iDRow = 0 To dtShareholders.Rows.Count - 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;iRColumn = 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Excel.Cells(iRRow, iRColumn).Value = dtShareholders.&amp;amp;_&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Rows(iDRow).ItemArray(0).ToString&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Excel.Cells(iRRow, iRColumn).EntireColumn.AutoFit()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Excel.Cells(iRRow, iRColumn).Borders.Weight = 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Excel.Cells(iRRow, iRColumn).Font.Bold = True&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Excel.Cells(iRRow, iRColumn).RowHeight = 15&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Excel.Cells(iRRow, iRColumn).HorizontalAlignment = xlLeft&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;iRRow = iRRow + 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Next&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Set the Selected Sheet in the Workbook&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial; font-style: italic;"&gt;Excel.Worksheets(1).select()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;Dim strFileName As String&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;strFileName = IO.Path.GetDirectoryName&amp;amp;_&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;(System.Reflection.Assembly.GetExecutingAssembly&amp;amp;_&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;.Location) &amp;amp; "\SheetName"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;If IO.File.Exists(strFileName &amp;amp; ".xls") Then&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;IO.File.Delete(strFileName &amp;amp; ".xls")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Save the active workbook into the given location and delete if there is any file with the same name on the same location already exist.&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;Excel.ActiveWorkbook().SaveAs(strFileName &amp;amp; ".xls")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Dim destination As String = dlgsave.FileName&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;''Check if the file Saved or not&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If destination &lt;&gt; "" Then&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If IO.File.Exists(destination) Then&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; IO.File.Delete(destination)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;End If&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;System.IO.File.Copy(strFileName &amp;amp; ".xls", destination&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;MessageBox.Show("Excel Sheet saved successfully",&amp;amp;_&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;MessageBox.Show("Report Is Not Saved, Operation Canceled By User",&amp;amp;_&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;End If&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;dlgsave.Dispose()&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-4158083787334500423?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/4158083787334500423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=4158083787334500423&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4158083787334500423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/4158083787334500423'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/export-data-from-dataset-or-datatable.html' title='Export Data from Dataset or Datatable to Excel File'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-7527874322778170378</id><published>2009-04-29T12:25:00.002+05:30</published><updated>2009-07-22T10:52:31.851+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Javascript - Event Handling</title><content type='html'>&lt;span style="font-family: arial;font-size:100%;" &gt;This code will help us to write any code before and after any event&lt;/span&gt;&lt;span style="font-size:100%;"&gt;. &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-style: italic;"&gt;BeforeAjaxRequest&lt;/span&gt; method will be executed before any event and &lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:100%;" &gt;&lt;span style="font-family: arial;"&gt;pageLoadedHandler&lt;/span&gt;&lt;/span&gt; method will be executed at the end of any event.&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample Syntax&lt;/span&gt;:&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;var pageMgr = Sys.WebForms.PageRequestManager.getInstance();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;pageMgr.add_beginRequest(BeforeAjaxRequest);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;pageMgr.add_pageLoaded(pageLoadedHandler);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;var postbackElement;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;function BeforeAjaxRequest(sender, args)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; postbackElement=args.get_postBackElement();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; if (postbackElement.id.indexOf("{&lt;span style="font-weight: bold;"&gt;ID of the Control&lt;/span&gt;}") != "-1")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;/* &lt;/span&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(0, 153, 0); font-weight: bold;font-size:85%;" &gt;Write your Code Here&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt; */&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;function pageLoadedHandler(sender, args)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   if (typeof(postbackElement) == "undefined") { return;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   else if (postbackElement.id.indexOf("&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;{ID of the Control}&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;") != "-1")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   {&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;/* Write your Code Here */&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;For Example&lt;/span&gt;: You are having a asp link button with id lnkTest now according to this your above code should be:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;function BeforeAjaxRequest(sender, args)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; postbackElement=args.get_postBackElement();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; if (postbackElement.id.indexOf("&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;lnkTest&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;") != "-1")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   {&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;alert("Before Ajax Request");&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;function pageLoadedHandler(sender, args)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   if (typeof(postbackElement) == "undefined") { return;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   else if (postbackElement.id.indexOf("&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;lnkTest&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;") != "-1")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   {&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial; font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;alert("After Ajax the Request"&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;);}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-7527874322778170378?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/7527874322778170378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=7527874322778170378&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7527874322778170378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/7527874322778170378'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/javascript-evnet-handling.html' title='Javascript - Event Handling'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2331298931466853000</id><published>2009-04-25T14:29:00.003+05:30</published><updated>2009-07-22T10:56:32.764+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Clock in Javascript</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;To Show Clock in Javascript  &lt;/span&gt;&lt;span style="font-family:arial;"&gt;(Time Format: SAT 4-25-2009 2:43:22 PM)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Function to create a array of given length&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;function MakeArray(size)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;this.length = size;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;for(var i = 1; i &lt;= size; i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;this[i] = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;return this;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Function to display time. in this at the end we write &lt;span style="font-style: italic;"&gt;setTimeout("showtime()",1000)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;.&lt;br /&gt;this code will call the showtime function after every second.&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;function showtime ()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var now = new Date();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var year = now.getYear();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var month = now.getMonth() + 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var date = now.getDate();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var hours = now.getHours();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var minutes = now.getMinutes();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var seconds = now.getSeconds();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var day = now.getDay();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Day = new MakeArray(7);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Day[0]="SUN";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Day[1]="MON";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Day[2]="TUE";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Day[3]="WED";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Day[4]="THU";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Day[5]="FRI";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Day[6]="SAT";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;var timeValue = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;timeValue += (Day[day]) + " ";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;timeValue += ((month &gt; 10) ? " 0" : " ") + month + "-";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;timeValue += date + "-" + year + " ";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;timeValue += ((hours &lt;= 12) ? hours : hours - 12);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;timeValue += ((minutes &lt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;timeValue += ((seconds &lt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;timeValue += (hours &lt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;document.getElementById('lblClock').innerHTML = timeValue;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;setTimeout("showtime()",1000);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Paste the above code in the script tag in Head section and add the following line after the closing of HTML tag:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;showtime();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Use a span to show the clock - id of span used in this code is lblClock&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2331298931466853000?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2331298931466853000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2331298931466853000&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2331298931466853000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2331298931466853000'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/javascript-clock.html' title='Clock in Javascript'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6130893616014222098</id><published>2009-04-25T12:29:00.002+05:30</published><updated>2009-07-22T10:59:16.052+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Export Data From Excel Sheet into Dataset- C#</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;"&gt;Procedure To Export Excel Sheet Data into Dataset With the help of OLEDB&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Connection String For Excel &amp;amp; Query to Fetch The Records:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(0, 153, 0);"&gt;string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file + ";Extended Properties=Excel 8.0;";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;Select Column1,Column2,Column3,Column4 from [Sheet1$]&lt;br /&gt;&lt;/span&gt;Sheet1 is the name of the sheet in the Excel file from where you want to get the records.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Complete Code to Get the Excel Sheet Data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;string file = "Physical path of the File"; (Like: D:\\Amt.xls)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file + ";Extended Properties=Excel 8.0;";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;string query = "Select Column1,Column2,Column3,Column4 from [Sheet1$]";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DataSet dataSet = new DataSet();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;using (OleDbConnection Connection = new OleDbConnection(constr))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;using (OleDbDataAdapter DataAdapter = new OleDbDataAdapter(query, Connection))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DataAdapter.Fill(dataSet, "DataSetName");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;DataAdapter.AcceptChangesDuringFill = false;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6130893616014222098?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6130893616014222098/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6130893616014222098&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6130893616014222098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6130893616014222098'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/get-data-from-excel-sheet-into-dataset.html' title='Export Data From Excel Sheet into Dataset- C#'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-6046001148932950396</id><published>2009-04-25T12:00:00.003+05:30</published><updated>2009-07-22T11:00:31.474+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Function To Send Email - ASP.NET (C#)</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;"&gt;User needs to pass few parameter to this method to send the mail.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;body - Content of email that you want to send.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;toadd - Address of the user to whom you want to send the Email.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;ccAdd - Address of the user to whom you want to send Email in CC.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;bccadd -Address of the user to whom you want to send Email in BCC.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;fromaddm - Address of the user that want to send the Email.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;subject - Subject of the Email.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;attachment - Attachment any if you want to send to user otherwise set the value as blank if you don't want to send any email.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Address of SMTP Server - Replace this text with the address of your SMTP Server.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;Code To Send Email:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;public static bool SendMail(string body, string toadd, string fromadd, string subject, string attachment, string ccAdd, string bccadd)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;string mailServerName = "Address of SMTP Server ";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;//MailMessage represents the e-mail being sent&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;using (MailMessage message = new MailMessage(fromadd, toadd, subject, body))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (attachment != "")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;message.Attachments.Add(new Attachment(attachment));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (bccadd != "")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;message.Bcc.Add(bccadd);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;message.IsBodyHtml = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;message.Priority = MailPriority.Normal;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SmtpClient mailClient = new SmtpClient();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;mailClient.Host = mailServerName;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;mailClient.UseDefaultCredentials = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;mailClient.Send(message);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;catch (SmtpException ex)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;return false;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;catch (Exception ex)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;return false;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-6046001148932950396?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/6046001148932950396/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=6046001148932950396&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6046001148932950396'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/6046001148932950396'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/function-to-send-email-aspnet-c.html' title='Function To Send Email - ASP.NET (C#)'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-2593270917491428683</id><published>2009-04-24T14:08:00.005+05:30</published><updated>2009-07-22T11:03:48.309+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>ASP.NET - Form Authentication Tutorial</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;"&gt;aspx.cs File's Content:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;On Button Click for Login&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;protected void Button1_Click(object sender, EventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SqlConnection con = new SqlConnection();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;con.ConnectionString = "server={ServerName};uid={UserID};pwd={Password};database={DatabaseName}";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;con.Open();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SqlCommand cm = new SqlCommand("select roles from users where username = '" + TextBox1.Text + "' and password = '" + TextBox2.Text + "'", con);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SqlDataReader dr = cm.ExecuteReader();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (dr.Read())&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;FormsAuthenticationTicket tk = new FormsAuthenticationTicket(1, TextBox1.Text, DateTime.Now, DateTime.Now.AddMinutes (1),true, dr.GetString(0),FormsAuthentication.FormsCookiePath);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;string hash = FormsAuthentication.Encrypt(tk);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;HttpCookie Logincookie = new HttpCookie(FormsAuthentication.FormsCookieName,hash);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Response.Cookies.Add(Logincookie);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (tk.IsPersistent)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;HttpCookie ck = new HttpCookie( FormsAuthentication.FormsCookieName, hash);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;ck.Expires = tk.Expiration;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Response.Cookies.Add(ck);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;string returnUrl = Request.QueryString["ReturnUrl"];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (returnUrl == null) returnUrl = "Main.aspx";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Response.Redirect(returnUrl);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Response.Write("The Username / Password not valid !");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;con.Close();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;dr.Close();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;cm.Dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Add These lines of code in Global.asax:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;protected void Application_AuthenticateRequest(Object sender, EventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (HttpContext.Current.User != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (HttpContext.Current.User.Identity.IsAuthenticated )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (HttpContext.Current.User.Identity is FormsIdentity)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;FormsAuthenticationTicket ticket = id.Ticket;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;HttpCookie ck = new HttpCookie("ticket");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;string userData = ticket.UserData;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;string[] roles = userData.Split(',');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;HttpContext.Current.User = new GenericPrincipal(id, roles);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;Database:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;font-size:85%;" &gt;&lt;span style="font-family: arial;"&gt;CREATE TABLE users&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;username nvarchar(64) CONSTRAINT users_PK PRIMARY KEY,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;password nvarchar(12,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;roles nvarchar(64)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;CREATE INDEX credentials ON users&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;username,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;password&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;insert into users values('client','client','c')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;insert into users values('admin','admin','a')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;select * from users&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Add These Lines in Web Config&lt;br /&gt;Before &amp;lt;/system.web&amp;gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;authentication mode="Forms"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;forms name="cookie" loginUrl="Default.aspx"&amp;gt; &amp;lt;/forms&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;/authentication&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;authorization&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;allow users="*"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;/allow&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;After &amp;lt;/system.web&amp;gt; &amp;amp; before &amp;lt;/configuration&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;location path="Admin"&amp;lt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;system.web&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;authorization&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;!-- Order and case are important below --&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;allow roles="a"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;deny users="*"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;/deny&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;/allow&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;/authorization&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;location path="Client"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;system.web&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;authorization&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;!-- Order and case are important below --&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;allow roles="c,a"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;deny users="*"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;/deny&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;/allow&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;&amp;lt;/authorization&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-2593270917491428683?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/2593270917491428683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=2593270917491428683&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2593270917491428683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/2593270917491428683'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/aspnet-form-authentication-tutorial.html' title='ASP.NET - Form Authentication Tutorial'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-3946571735906840305</id><published>2009-04-24T14:05:00.003+05:30</published><updated>2009-07-22T11:12:44.697+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Microsoft SQL Server - Create Web Service</title><content type='html'>&lt;span style="font-size:100%;"&gt; first line is to Create End Point for web service.&lt;/span&gt;&lt;br /&gt;State can be of three types: &lt;span style="font-size:100%;"&gt;STARTED Means Listening and Responding, DISABLED Means Neither Listening nor Responding And STOPPED Means Listening But Not Responding&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; specify the Transport Protocol to used&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;{HTTP | TCP} &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;Authentication mode is of three types INTEGRATED Is More Secure, While Basic is Least Secure and Digest is not Secure Authentication type&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;CLEAR (HTTP - port 80 by default) SSL (HTTPS - port 443 by default) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;PORTS= {CLEAR | SSL}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;BATCHES= {ENABLED | DISABLED}&lt;/span&gt;&lt;br /&gt; if ENABLED, multiple SOAP request/response message pairs can be identified as part of a single SOAP session.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;CREATE ENDPOINT XMLHTTPEndPoint &lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;STATE= {STARTED | STOPPED | DISABLED}&lt;br /&gt;AS&lt;br /&gt;{HTTP | TCP}&lt;br /&gt;(&lt;br /&gt;PATH = &lt;path&gt; (e.g.: '/Webservices',)&lt;br /&gt;AUTHENTICATION= (BASIC | DIGEST | INTEGRATED),&lt;br /&gt;PORTS= {CLEAR | SSL},&lt;br /&gt;SITE= &lt;server&gt;&lt;br /&gt;)&lt;br /&gt;FOR {SOAP | TSQL}&lt;br /&gt; (&lt;br /&gt;WEBMETHOD &lt;web&gt;&lt;br /&gt;(NAME=&lt;database.schema.name&gt;),&lt;br /&gt;BATCHES= {ENABLED | DISABLED},&lt;br /&gt;WSDL= {NONE | DEFAULT | 'sp_name'},DATABASE = &amp;lt;Database Name&gt;&amp;gt;&lt;br /&gt;NAMESPACE= http://&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&amp;lt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;Server Name&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&amp;gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;/( Name where you want to create Web service)&lt;br /&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;WSDL Specify how the Document Generation Will Occur. If none no Response is generated or returned for query.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-3946571735906840305?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/3946571735906840305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=3946571735906840305&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/3946571735906840305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/3946571735906840305'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/microsoft-sql-server-create-web-service.html' title='Microsoft SQL Server - Create Web Service'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-5294018529756447533</id><published>2009-04-24T12:21:00.004+05:30</published><updated>2009-07-22T11:16:40.121+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><title type='text'>Microsoft SQL Server - Important Queries</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;Query to Select n Rendom Records From a Table in the Database:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;SELECT TOP 3 * FROM Tbl_WZQ_REGISTRATION ORDER By NEWID()&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Null Parameter check in the query- we can add this check in the where condition&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;(&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;@VariableData is NULL OR [ColumnName] = @VariableData&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Get File Extension from given File Name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;DECLARE @FileName VARCHAR(200)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SET @FileName='MyFile.ppt'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SELECT SUBSTRING(@FileName,(LEN(@FileName) - CHARINDEX('.', REVERSE(@FileName), 1 + 1)+2) ,LEN(@FileName)) AS Ext&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="font-weight: bold;"&gt;OUTPUT:&lt;/span&gt; ppt&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;To Get The Column Name,DataType, And&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Length of columns in a Table&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;select column_name, data_type, character_maximum_length from information_schema.columns&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;where table_name ={Table Name}&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Views&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from information_schema.views&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Tables&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from information_schema.Tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of System Tables&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='s'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of User Tables&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='u'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Store Procedures&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='p'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Scalar Functions&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='fn'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Table Valued Functions&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='tf'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Primary Keys&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='PK'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Unique Keys&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='uq'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Forgien Keys&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='f'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of views&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='v'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Triggers&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='tr'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Query to Get List of Internal Tables&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 153, 0);font-family:arial;font-size:85%;"  &gt;select * from Sys.Objects where Type='it'&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-5294018529756447533?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/5294018529756447533/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=5294018529756447533&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5294018529756447533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/5294018529756447533'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2009/04/microsoft-sql-server-cross-tab-query.html' title='Microsoft SQL Server - Important Queries'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643476320867117891.post-9167777736876645175</id><published>2008-09-18T11:27:00.004+05:30</published><updated>2009-07-22T11:25:46.329+05:30</updated><title type='text'>About Me</title><content type='html'>&lt;span style="text-decoration: underline;"&gt;&lt;strong&gt;About Our Guru ji:&lt;/strong&gt;&lt;/span&gt;&lt;p&gt;&lt;strong style="color: rgb(255, 102, 0);"&gt;Baba G&lt;/strong&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_Kp--fzJWFmc/SNH0zXqUe8I/AAAAAAAAADI/QYSdeYeSG7Y/s1600-h/baba+ji.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5247244204225362882" style="margin: 0pt 10px 10px 0pt; float: left; width: 178px; cursor: pointer; height: 140px;" alt="" src="http://1.bp.blogspot.com/_Kp--fzJWFmc/SNH0zXqUe8I/AAAAAAAAADI/QYSdeYeSG7Y/s320/baba+ji.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong style="color: rgb(255, 102, 0);"&gt;endhi Ram&lt;/strong&gt;&lt;span style="color: rgb(255, 102, 0);"&gt; ji&lt;/span&gt;’s Dera is situated at a distance of 3 km from &lt;strong&gt;Dharamkot&lt;/strong&gt; on Dharamkot- Jalandhar Road. Dera is running by a trust under the guidance of President Pandit Joginder Daas ji.&lt;/p&gt;&lt;p&gt;“Guru ka Langar” is arranged by Trust with the help of the people of the Dharamkot in “&lt;strong&gt;Sawan&lt;/strong&gt;” (For One Month) and near “&lt;strong&gt;Holi&lt;/strong&gt;” (for 10 or 12 days).&lt;/p&gt;&lt;p&gt;Baba ji’s Barsi is celebrated on 11th of may. people from different parts of the punjab and other states come on this occusion to get the blessing of baba ji.&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;&lt;u&gt;About Me&lt;/u&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_Kp--fzJWFmc/SNHuvmFdFlI/AAAAAAAAADA/_0_paOqCr5o/s1600-h/lakhan.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5247237542308025938" style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" alt="" src="http://3.bp.blogspot.com/_Kp--fzJWFmc/SNHuvmFdFlI/AAAAAAAAADA/_0_paOqCr5o/s320/lakhan.jpg" width="100" border="2" height="150" /&gt;&lt;/a&gt;&lt;/p&gt;My Self &lt;strong style="color: rgb(0, 0, 0);"&gt;Lakhan Pal Garg&lt;/strong&gt;. I am a B.Tech (I.T ) graduate. i have completed my graduation in July 2005.&lt;p style="text-align: justify;"&gt;&lt;strong&gt;Profession&lt;/strong&gt; : Software Developer (Mainly Working on Website Development in Microsoft Technologies like ASP.NET, C#, VB.NET, MS-SOL Server)&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Somthing About My Carrier:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style="text-align: justify;"&gt;I had started my professional carrier with &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Hanu Software Solutions&lt;/span&gt;&lt;/strong&gt;, Gurgaon in June 2006, after that i joined &lt;span style="text-decoration: underline;"&gt;&lt;strong&gt;Safaltek Software Pvt. Ltd&lt;/strong&gt;&lt;/span&gt;, Chandigarh in Nov 2006. i worked with Safaltek for near about 9 Months and worked on various application (both web and desktop application). i also worked on &lt;span style="color: rgb(255, 102, 0);"&gt;&lt;strong&gt;Microsoft Share Point Portal server&lt;/strong&gt;&lt;/span&gt; in Safaltek, Then i moved to &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Sebiz Infotech, Mohali&lt;/span&gt;&lt;/strong&gt; in Aug 2007 and worked there till Aug 2008. Currently i am working with &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Authorgen Pvt. Ltd., Chandigarh&lt;/span&gt;&lt;/strong&gt; as Senior Software Engineer. i am working on the one of their product named &lt;strong&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Wiziq.com&lt;/span&gt;&lt;/strong&gt; (a online virtual class based educational web site).&lt;/p&gt;&lt;p style="text-align: justify;"&gt;&lt;strong&gt;Links of some sites on which i have worked:&lt;/strong&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;p style="text-align: justify;"&gt;&lt;a title="wiziq.com" href="http://www.wiziq.com/"&gt;http://www.wiziq.com/&lt;/a&gt;&lt;br /&gt;&lt;a title="amuktrade.com" href="http://www.amuktrade.com/"&gt;http://www.amuktrade.com/&lt;/a&gt;&lt;br /&gt;&lt;a title="amuktrade.com" href="http://www.turningpages.com/"&gt;http://www.turningpages.com/&lt;/a&gt;&lt;br /&gt;&lt;a title="kaatskillmtnclub.com" href="http://www.kaatskillmtnclub.com/"&gt;http://www.kaatskillmtnclub.com/&lt;/a&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;p style="text-align: justify;"&gt;&lt;span style="text-decoration: underline;"&gt;&lt;strong&gt;About My Family:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;p style="text-align: justify;"&gt;Father Name: &lt;strong&gt;Sh. Varinder Kumar Garg&lt;/strong&gt;&lt;/p&gt;&lt;p style="text-align: justify;"&gt;&lt;strong&gt;&lt;/strong&gt;Mother Name: &lt;strong&gt;Sm&lt;/strong&gt;&lt;strong&gt;t. Kamal Rani Garg&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;p style="text-align: justify;"&gt;Brother: &lt;span style="font-weight: bold;"&gt;Naveen&lt;/span&gt; &lt;strong&gt;Kumar Garg&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style="text-align: justify;"&gt;Wife: &lt;strong&gt;Aastha Garg&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1643476320867117891-9167777736876645175?l=lakhangarg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lakhangarg.blogspot.com/feeds/9167777736876645175/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1643476320867117891&amp;postID=9167777736876645175&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/9167777736876645175'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643476320867117891/posts/default/9167777736876645175'/><link rel='alternate' type='text/html' href='http://lakhangarg.blogspot.com/2008/09/about-me.html' title='About Me'/><author><name>Lakhan Pal Garg</name><uri>http://www.blogger.com/profile/03990328532714851479</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_Kp--fzJWFmc/SNH1SzkEZoI/AAAAAAAAADU/W0bjZKqem6s/S220/lakhan.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_Kp--fzJWFmc/SNH0zXqUe8I/AAAAAAAAADI/QYSdeYeSG7Y/s72-c/baba+ji.jpg' height='72' width='72'/><thr:total>2</thr:total></entry></feed>
