<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Fransiscus Setiawan .NET Blog</title>
	<atom:link href="http://fransiscuss.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fransiscuss.com</link>
	<description>My notepad to share knowledge with others</description>
	<pubDate>Tue, 17 Aug 2010 05:28:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Enter button in TextBox ASP.NET</title>
		<link>http://fransiscuss.com/enter-button-in-textbox-aspnet/</link>
		<comments>http://fransiscuss.com/enter-button-in-textbox-aspnet/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 05:28:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Keypress]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=276</guid>
		<description><![CDATA[This article is demonstrating how to wire up an enter key into a textbox. For example you have a search text box where you press enter then it will click go button and at the same page you have another textbox where you want to do another button click when you press the enter which [...]]]></description>
			<content:encoded><![CDATA[<p>This article is demonstrating how to wire up an enter key into a textbox. For example you have a search text box where you press enter then it will click go button and at the same page you have another textbox where you want to do another button click when you press the enter which means it&#8217; is not necessary to post the page. This java script is used to capture the key event of enter and execute the LinkButton and ASP.NET button Click Event on the server side. Please add this javascript to your javascript common library or add this to your master page. This piece of code works in Firefox as well</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ButtonKeyPress<span style="color: #009900;">&#40;</span>evt<span style="color: #339933;">,</span> thisElementName<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">which</span> || evt.<span style="color: #660066;">keyCode</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> || <span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// alert('post back href: ' +document.getElementById(thisElementName).href);</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>thisElementName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                location <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>thisElementName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">href</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>thisElementName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And add this to your .NET code behind on the page load</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"> Protected <span style="color: #b1b100;">Sub</span> Page_Load<span style="color: #66cc66;">&#40;</span>ByVal sender <span style="color: #b1b100;">As</span> Object, ByVal e <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">EventArgs</span><span style="color: #66cc66;">&#41;</span> Handles <span style="color: #b1b100;">Me</span>.<span style="color: #66cc66;">Load</span>
         <span style="color: #b1b100;">If</span> <span style="color: #b1b100;">Not</span> Page.<span style="color: #66cc66;">IsPostBack</span> <span style="color: #b1b100;">Then</span>
&nbsp;
&nbsp;
            <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>User.<span style="color: #66cc66;">Identity</span>.<span style="color: #66cc66;">IsAuthenticated</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                Response.<span style="color: #66cc66;">Redirect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;frmTimeMain.aspx&quot;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
            txtGUID.<span style="color: #66cc66;">Attributes</span>.<span style="color: #66cc66;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onkeydown&quot;</span>, <span style="color: #ff0000;">&quot;ButtonKeyPress(event, '&quot;</span> + lnkSubmit.<span style="color: #66cc66;">ClientID</span> + <span style="color: #ff0000;">&quot;')&quot;</span><span style="color: #66cc66;">&#41;</span>
            txtPassword.<span style="color: #66cc66;">Attributes</span>.<span style="color: #66cc66;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onkeydown&quot;</span>, <span style="color: #ff0000;">&quot;ButtonKeyPress(event, '&quot;</span> + lnkSubmit.<span style="color: #66cc66;">ClientID</span> + <span style="color: #ff0000;">&quot;')&quot;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/enter-button-in-textbox-aspnet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASP.NET Calendar selected day on click method</title>
		<link>http://fransiscuss.com/aspnet-calendar-selected-day-on-click-method/</link>
		<comments>http://fransiscuss.com/aspnet-calendar-selected-day-on-click-method/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 05:17:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Calendar]]></category>

		<category><![CDATA[Calendar javascript]]></category>

		<category><![CDATA[Calendar Selected Date]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=274</guid>
		<description><![CDATA[I&#8217;ve a case where I have an ASP.NET calendar that has a page load method that automatically select a date when it&#8217;s loaded. I also have an event defined for Selected_Changed which will be triggered only when the user select any other date other than pre-selected date on the load

Private Sub ctlCalendar_SelectionChanged&#40;ByVal sender As Object, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve a case where I have an ASP.NET calendar that has a page load method that automatically select a date when it&#8217;s loaded. I also have an event defined for Selected_Changed which will be triggered only when the user select any other date other than pre-selected date on the load</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"><span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> ctlCalendar_SelectionChanged<span style="color: #66cc66;">&#40;</span>ByVal sender <span style="color: #b1b100;">As</span> Object, ByVal e <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">EventArgs</span><span style="color: #66cc66;">&#41;</span> Handles ctlCalendar.<span style="color: #66cc66;">SelectionChanged</span>
        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">Not</span> <span style="color: #b1b100;">String</span>.<span style="color: #66cc66;">IsNullOrEmpty</span><span style="color: #66cc66;">&#40;</span>CalendarPreviousPage<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
            BaseCalendar.<span style="color: #66cc66;">SelectedDate</span> = ctlCalendar.<span style="color: #66cc66;">SelectedDate</span>
            Response.<span style="color: #66cc66;">Redirect</span><span style="color: #66cc66;">&#40;</span>CalendarPreviousPage<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span></pre></div></div>

<p>But how do I wire up an event or when the selecteddate being clicked?You can use DayRender event and attach it to a javascript in this case I want to go back to previous page. BaseCalendar.Selected date can be any date where you want to set up/wire up the logic</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"> <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> ctlCalendar_DayRender<span style="color: #66cc66;">&#40;</span>ByVal sender <span style="color: #b1b100;">As</span> Object, ByVal e <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">Web</span>.<span style="color: #66cc66;">UI</span>.<span style="color: #66cc66;">WebControls</span>.<span style="color: #66cc66;">DayRenderEventArgs</span><span style="color: #66cc66;">&#41;</span> Handles ctlCalendar.<span style="color: #66cc66;">DayRender</span>
        <span style="color: #b1b100;">Dim</span> d <span style="color: #b1b100;">As</span> CalendarDay
        <span style="color: #b1b100;">Dim</span> c <span style="color: #b1b100;">As</span> TableCell
        d = e.<span style="color: #b1b100;">Day</span>
        c = e.<span style="color: #66cc66;">Cell</span>
&nbsp;
        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>BaseCalendar.<span style="color: #66cc66;">SelectedDate</span>.<span style="color: #66cc66;">Value</span> = d.<span style="color: #b1b100;">Date</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
            c.<span style="color: #66cc66;">Attributes</span>.<span style="color: #66cc66;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;OnClick&quot;</span>, <span style="color: #ff0000;">&quot;history.go(-1)&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/aspnet-calendar-selected-day-on-click-method/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting the Silverlight (Telerik) RadGrid Culture</title>
		<link>http://fransiscuss.com/setting-the-silverlight-telerik-radgrid-culture/</link>
		<comments>http://fransiscuss.com/setting-the-silverlight-telerik-radgrid-culture/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 00:05:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[Culture]]></category>

		<category><![CDATA[RadGridView]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=267</guid>
		<description><![CDATA[I have this date column and it has DateConverter that i created to apply the current thread culture. The problem that I have is
-On load it display the date format perfectly based on the current culture
-The problem is when i double click the cell/edit mode then it applies different format but then when i exit [...]]]></description>
			<content:encoded><![CDATA[<p>I have this date column and it has DateConverter that i created to apply the current thread culture. The problem that I have is<br />
-On load it display the date format perfectly based on the current culture<br />
-The problem is when i double click the cell/edit mode then it applies different format but then when i exit edit mode then it shows the right formatting</p>
<p>e.g<br />
on load the cell display 07/08/2010 (07th August 2010) but when I go to edit mode it shows as 08/07/2010 (08th July 2010) but again when I finish editing then it shows 07/08/2010</p>
<p>so basically my current thread date format is dd/mm/yyyy but in edit mode it applies the us formatting which is mm/dd/yyyy. Finally I found out how to set the grid culture</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"><span style="color: #b1b100;">Dim</span> _LocaleLanguage <span style="color: #b1b100;">as</span> <span style="color: #b1b100;">String</span> = .<span style="color: #b1b100;">String</span>.<span style="color: #66cc66;">Empty</span>
&nbsp;
_LocaleLanguage = CultureInfo.<span style="color: #66cc66;">CreateSpecificCulture</span><span style="color: #66cc66;">&#40;</span>System.<span style="color: #66cc66;">Web</span>.<span style="color: #66cc66;">HttpContext</span>.<span style="color: #66cc66;">Current</span>.<span style="color: #66cc66;">Request</span>.<span style="color: #66cc66;">UserLanguages</span><span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #b1b100;">Name</span>.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
dgResults.<span style="color: #66cc66;">Language</span> = Windows.<span style="color: #66cc66;">Markup</span>.<span style="color: #66cc66;">XmlLanguage</span>.<span style="color: #66cc66;">GetLanguage</span><span style="color: #66cc66;">&#40;</span>_LocaleLanguage<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Viola!! and it solves my culture problem</p>
]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/setting-the-silverlight-telerik-radgrid-culture/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Read and Update XML Node of XML datatype in SQL Server</title>
		<link>http://fransiscuss.com/read-and-update-xml-node-of-xml-datatype-in-sql-server/</link>
		<comments>http://fransiscuss.com/read-and-update-xml-node-of-xml-datatype-in-sql-server/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 00:04:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SQL Server]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[XML SQL Server]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=265</guid>
		<description><![CDATA[
Select Node value

This is a simple explanation on how to select a particular node from xml data type of a record in SQL server.
Sample XML

&#60;iReference&#62;
  &#60;chAuditorCode IsChanged=&#34;false&#34;&#62;00003479&#60;/chAuditorCode&#62;
  &#60;vcAuditorDesc IsChanged=&#34;true&#34;&#62;Brodie's HomeSton&#60;/vcAuditorDesc&#62;
  &#60;sdTermDate IsChanged=&#34;false&#34;&#62;NULL&#60;/sdTermDate&#62;
  &#60;Action /&#62;
  &#60;Comment /&#62;
  &#60;chUpdateStaffCode&#62;AU941170&#60;/chUpdateStaffCode&#62;
  &#60;dtUpdateDateTime&#62;2010-07-22T09:42:20&#60;/dtUpdateDateTime&#62;
  &#60;ChangedColumns&#62;vcAuditorDesc,chUpdateStaffCode,dtUpdateDateTime,dtUpdateDateTime&#60;/ChangedColumns&#62;
&#60;/iReference&#62;

So what I want to do is basically to [...]]]></description>
			<content:encoded><![CDATA[<p><strong><br />
Select Node value<br />
</strong><br />
This is a simple explanation on how to select a particular node from xml data type of a record in SQL server.</p>
<p>Sample XML</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;iReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chAuditorCode</span> <span style="color: #000066;">IsChanged</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>00003479<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chAuditorCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vcAuditorDesc</span> <span style="color: #000066;">IsChanged</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Brodie's HomeSton<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vcAuditorDesc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdTermDate</span> <span style="color: #000066;">IsChanged</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>NULL<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdTermDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Action</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Comment</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chUpdateStaffCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AU941170<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chUpdateStaffCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dtUpdateDateTime<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2010-07-22T09:42:20<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dtUpdateDateTime<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ChangedColumns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>vcAuditorDesc,chUpdateStaffCode,dtUpdateDateTime,dtUpdateDateTime<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ChangedColumns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/iReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>So what I want to do is basically to get the value of ChangedColumns node</p>

<div class="wp_syntax"><div class="code"><pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>  xmlDetail<span style="color: #66cc66;">.</span>value<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/iReference[1]/ChangedColumns[1]/.'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(255)'</span><span style="color: #66cc66;">&#41;</span>  
<span style="color: #993333; font-weight: bold;">FROM</span> tblReferenceHistory
<span style="color: #993333; font-weight: bold;">WHERE</span> intReferenceHistoryID <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">125</span></pre></div></div>

<p><strong><br />
Update Existing Node value<br />
</strong></p>
<p>Sample XML</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;iReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chAuditorCode</span> <span style="color: #000066;">IsChanged</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>00003479<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chAuditorCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vcAuditorDesc</span> <span style="color: #000066;">IsChanged</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Brodie's HomeSton<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vcAuditorDesc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdTermDate</span> <span style="color: #000066;">IsChanged</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>NULL<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdTermDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Action</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Comment</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chUpdateStaffCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AU941170<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chUpdateStaffCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dtUpdateDateTime<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2010-07-22T09:42:20<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dtUpdateDateTime<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ChangedColumns</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/iReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Changed column has no value in it and you want to update it. Basically you can&#8217;t edit the existing node value so what you need to do is to readd it and remove the first instance of that node</p>

<div class="wp_syntax"><div class="code"><pre class="sql sql" style="font-family:monospace;">DECLARE @ChangedColumns VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> @ChangedColumns <span style="color: #66cc66;">=</span> xmlDetail<span style="color: #66cc66;">.</span>value<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/iReference[1]/ChangedColumns[1]/.'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(255)'</span><span style="color: #66cc66;">&#41;</span>  
<span style="color: #993333; font-weight: bold;">FROM</span> tblReferenceHistory
<span style="color: #993333; font-weight: bold;">WHERE</span> intReferenceHistoryID <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">125</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- first update - add a new &lt;ChangedColumns&gt;...&lt;/ChangedColumns&gt; node    </span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> tblReferenceHistory
<span style="color: #993333; font-weight: bold;">SET</span> xmlDetail<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">MODIFY</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'insert &lt;ChangedColumns&gt;{sql:variable(&quot;@ChangedColumns&quot;)}&lt;/ChangedColumns&gt; as last into (/iReference)[1]'</span><span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">WHERE</span> intReferenceHistoryID <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">124</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- second update - remove the empty &lt;ChangedColumns /&gt; node    </span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> dbo<span style="color: #66cc66;">.</span>tblReferenceHistory
<span style="color: #993333; font-weight: bold;">SET</span> xmlDetail<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">MODIFY</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'delete (/iReference[1]/ChangedColumns[1])[1]'</span><span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">WHERE</span> intReferenceHistoryID <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">124</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> xmlDetail<span style="color: #66cc66;">.</span>value<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/iReference[1]/ChangedColumns[1]/.'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(255)'</span><span style="color: #66cc66;">&#41;</span>  
<span style="color: #993333; font-weight: bold;">FROM</span> tblReferenceHistory
<span style="color: #993333; font-weight: bold;">WHERE</span> intReferenceHistoryID <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">124</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/read-and-update-xml-node-of-xml-datatype-in-sql-server/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to set variable from Dynamic SQL</title>
		<link>http://fransiscuss.com/how-to-set-variable-from-dynamic-sql/</link>
		<comments>http://fransiscuss.com/how-to-set-variable-from-dynamic-sql/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 05:07:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SQL Server]]></category>

		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=259</guid>
		<description><![CDATA[Here is the scenario, You have a stored procedure that builds dynamic insert SQL which means the &#8220;INSERT&#8221; statement is being composed on the fly based on the table name but at the same time you need to get SCOPE_IDENTITY or the last identity number inserted for further processing (e.g History table)

	DECLARE @nvcSQL			NVARCHAR&#40;MAX&#41;	
	DECLARE @pvcTableName	VARCHAR&#40;255&#41;
	DECLARE @pvcColumn		VARCHAR&#40;255&#41;
	DECLARE [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the scenario, You have a stored procedure that builds dynamic insert SQL which means the &#8220;INSERT&#8221; statement is being composed on the fly based on the table name but at the same time you need to get SCOPE_IDENTITY or the last identity number inserted for further processing (e.g History table)</p>

<div class="wp_syntax"><div class="code"><pre class="sql sql" style="font-family:monospace;">	DECLARE @nvcSQL			NVARCHAR<span style="color: #66cc66;">&#40;</span>MAX<span style="color: #66cc66;">&#41;</span>	
	DECLARE @pvcTableName	VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
	DECLARE @pvcColumn		VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
	DECLARE @pvcValue		NVARCHAR<span style="color: #66cc66;">&#40;</span>MAX<span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">--This is used to actually get the primary key for identity record</span>
	DECLARE @dvcPrimaryKey VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> 
	<span style="color: #993333; font-weight: bold;">SET</span> @dvcPrimaryKey <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span>
&nbsp;
	DECLARE @dintPrimaryKey INT	
	<span style="color: #993333; font-weight: bold;">SELECT</span> @dvcPrimaryKey <span style="color: #66cc66;">=</span> ISNULL<span style="color: #66cc66;">&#40;</span>NAME<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> SYS<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">COLUMNS</span> <span style="color: #993333; font-weight: bold;">WHERE</span> OBJECT_NAME<span style="color: #66cc66;">&#40;</span>OBJECT_ID<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> @pvcTableName <span style="color: #993333; font-weight: bold;">AND</span> Is_Identity <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span> 
&nbsp;
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Only execute when there is a @pvcValue.</span>
	<span style="color: #993333; font-weight: bold;">IF</span> @pvcValue <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
	BEGIN
		<span style="color: #993333; font-weight: bold;">SELECT</span> @nvcSQL <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'INSERT INTO '</span> <span style="color: #66cc66;">+</span> @pvcTableName <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'('</span> <span style="color: #66cc66;">+</span> @pvcColumn<span style="color: #66cc66;">+</span> <span style="color: #ff0000;">') VALUES ('</span> <span style="color: #66cc66;">+</span> @pvcValue <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">')'</span>
		<span style="color: #993333; font-weight: bold;">SELECT</span> @nvcSQL <span style="color: #66cc66;">=</span> @nvcSQL <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">';'</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'SELECT @dintPrimaryKey = SCOPE_IDENTITY()'</span>
		<span style="color: #808080; font-style: italic;">--PRINT @nvcSQL</span>
&nbsp;
		EXEC sp_executesql @query <span style="color: #66cc66;">=</span> @nvcSQL<span style="color: #66cc66;">,</span> @params <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">'@dintPrimaryKey INT OUTPUT'</span><span style="color: #66cc66;">,</span> @dintPrimaryKey <span style="color: #66cc66;">=</span> @dintPrimaryKey OUTPUT 
		<span style="color: #808080; font-style: italic;">--EXEC (@nvcSQL)</span>
	END
&nbsp;
	<span style="color: #993333; font-weight: bold;">IF</span> @dvcPrimaryKey <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">''</span>
	BEGIN
		<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#40;</span>@dvcPrimaryKey <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' = '</span> <span style="color: #66cc66;">+</span> CAST<span style="color: #66cc66;">&#40;</span>@dintPrimaryKey <span style="color: #993333; font-weight: bold;">AS</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #993333; font-weight: bold;">AS</span> PrimaryKey 
	END
	ELSE
	BEGIN
		<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">''</span> <span style="color: #993333; font-weight: bold;">AS</span> PrimaryKey
	END</pre></div></div>

<p>Question: why do we need to use sp_executesql instead of EXEC?because EXEC just execute a SQL command without returning/expecting any result from it</p>
]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/how-to-set-variable-from-dynamic-sql/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Telerik SL Gridview Cell Foreground color dynamically based on multiple binding</title>
		<link>http://fransiscuss.com/telerik-sl-gridview-cell-foreground-color-dynamically-based-on-multiple-binding/</link>
		<comments>http://fransiscuss.com/telerik-sl-gridview-cell-foreground-color-dynamically-based-on-multiple-binding/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 03:25:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Cell Converter]]></category>

		<category><![CDATA[ItemDatabound]]></category>

		<category><![CDATA[RadGridView Silverlight]]></category>

		<category><![CDATA[Telerik]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=256</guid>
		<description><![CDATA[I had a problem before where I build dynamic system (light dataset) for doing CRUD (Create, Read, Update and Delete) and I need to store the history of previous record before Update/Delete and at the same time I also need to indicate the column(e.g changing the color of the column) that has been changed per [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem before where I build dynamic system (light dataset) for doing CRUD (Create, Read, Update and Delete) and I need to store the history of previous record before Update/Delete and at the same time I also need to indicate the column(e.g changing the color of the column) that has been changed per record in history table. I&#8217;ve been struggling for a day in order to accomplish this.</p>
<p>1. You need to add reference and import System.Windows.Interactivity from SL3 SDK<br />
2. Create a TableHistoryColorConverter.vb</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Data</span>
Imports System.<span style="color: #66cc66;">Globalization</span>
Imports System.<span style="color: #66cc66;">Reflection</span>
&nbsp;
<span style="color: #b1b100;">Public</span> Class TableHistoryColorConverter
    <span style="color: #b1b100;">Implements</span> IValueConverter
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Convert<span style="color: #66cc66;">&#40;</span>ByVal value <span style="color: #b1b100;">As</span> Object, ByVal targetType <span style="color: #b1b100;">As</span> System.<span style="color: #b1b100;">Type</span>, ByVal parameter <span style="color: #b1b100;">As</span> Object, ByVal culture <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">Globalization</span>.<span style="color: #66cc66;">CultureInfo</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Object <span style="color: #b1b100;">Implements</span> System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Data</span>.<span style="color: #66cc66;">IValueConverter</span>.<span style="color: #66cc66;">Convert</span>
        <span style="color: #b1b100;">Dim</span> cellColor <span style="color: #b1b100;">As</span> SolidColorBrush = <span style="color: #b1b100;">New</span> SolidColorBrush<span style="color: #66cc66;">&#40;</span>Colors.<span style="color: #66cc66;">Black</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        Try
&nbsp;
            <span style="color: #b1b100;">Dim</span> columnList <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = value.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> currentColumnName <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = parameter.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #808080;">'Dim changeColumnParam As String = parameter.ToString()</span>
            <span style="color: #b1b100;">Dim</span> changedColumnList <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = columnList.<span style="color: #b1b100;">Split</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">New</span> Char<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;,&quot;</span>c<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            <span style="color: #b1b100;">If</span> changedColumnList.<span style="color: #66cc66;">Contains</span><span style="color: #66cc66;">&#40;</span>currentColumnName<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                cellColor = <span style="color: #b1b100;">New</span> SolidColorBrush<span style="color: #66cc66;">&#40;</span>Colors.<span style="color: #66cc66;">Red</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
        Catch ex <span style="color: #b1b100;">As</span> Exception
&nbsp;
        <span style="color: #b1b100;">End</span> Try
&nbsp;
        <span style="color: #b1b100;">Return</span> cellColor
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> ConvertBack<span style="color: #66cc66;">&#40;</span>ByVal value <span style="color: #b1b100;">As</span> Object, ByVal targetType <span style="color: #b1b100;">As</span> System.<span style="color: #b1b100;">Type</span>, ByVal parameter <span style="color: #b1b100;">As</span> Object, ByVal culture <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">Globalization</span>.<span style="color: #66cc66;">CultureInfo</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Object <span style="color: #b1b100;">Implements</span> System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Data</span>.<span style="color: #66cc66;">IValueConverter</span>.<span style="color: #66cc66;">ConvertBack</span>
        Throw <span style="color: #b1b100;">New</span> Exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Not Implemented&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
<span style="color: #b1b100;">End</span> Class</pre></div></div>

<p>3. Create a vb class file called HistoryRecordFormatting.vb</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #b1b100;">Input</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Media</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Media</span>.<span style="color: #66cc66;">Animation</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Shapes</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Interactivity</span>
Imports Telerik.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Controls</span>
Imports Telerik.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Controls</span>.<span style="color: #66cc66;">GridView</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Data</span>
Imports SLCoreLib
&nbsp;
<span style="color: #b1b100;">Public</span> Class HistoryRecordFormatting
    Inherits Behavior<span style="color: #66cc66;">&#40;</span>Of RadGridView<span style="color: #66cc66;">&#41;</span>
&nbsp;
    Protected Overrides <span style="color: #b1b100;">Sub</span> OnAttached<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        MyBase.<span style="color: #66cc66;">OnAttached</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        AddHandler AssociatedObject.<span style="color: #66cc66;">RowLoaded</span>, <span style="color: #b1b100;">New</span> EventHandler<span style="color: #66cc66;">&#40;</span>Of Telerik.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Controls</span>.<span style="color: #66cc66;">GridView</span>.<span style="color: #66cc66;">RowLoadedEventArgs</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>AddressOf AssociatedObject_RowLoaded<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
&nbsp;
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> AssociatedObject_RowLoaded<span style="color: #66cc66;">&#40;</span>ByVal sender <span style="color: #b1b100;">As</span> Object, ByVal e <span style="color: #b1b100;">As</span> Telerik.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Controls</span>.<span style="color: #66cc66;">GridView</span>.<span style="color: #66cc66;">RowLoadedEventArgs</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>TypeOf e.<span style="color: #66cc66;">Row</span> Is GridViewHeaderRow<span style="color: #66cc66;">&#41;</span> OrElse <span style="color: #66cc66;">&#40;</span>TypeOf e.<span style="color: #66cc66;">Row</span> Is GridViewFooterRow<span style="color: #66cc66;">&#41;</span> OrElse <span style="color: #66cc66;">&#40;</span>TypeOf e.<span style="color: #66cc66;">Row</span> Is GridViewNewRow<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
            <span style="color: #b1b100;">Return</span>
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
&nbsp;
        <span style="color: #b1b100;">For</span> Each cell In e.<span style="color: #66cc66;">Row</span>.<span style="color: #66cc66;">Cells</span>
            <span style="color: #808080;">'we want to apply logic to data rows only</span>
            <span style="color: #808080;">'ChangedColumns is the list of the column that has been edited (comma separated value) for that history record</span>
            <span style="color: #b1b100;">Dim</span> colorBinding <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> Binding<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ChangedColumns&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">With</span> <span style="color: #66cc66;">&#123;</span> _
                .<span style="color: #66cc66;">Converter</span> = <span style="color: #b1b100;">New</span> TableHistoryColorConverter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, .<span style="color: #66cc66;">ConverterParameter</span> = cell.<span style="color: #66cc66;">Column</span>.<span style="color: #66cc66;">UniqueName</span> _
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            cell.<span style="color: #66cc66;">SetBinding</span><span style="color: #66cc66;">&#40;</span>GridViewCell.<span style="color: #66cc66;">ForegroundProperty</span>, colorBinding<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Next</span>
        <span style="color: #808080;">'e.Row.Cells(1).SetBinding(GridViewCell.ForegroundProperty, colorBinding)</span>
        <span style="color: #808080;">'e.Row.Cells[1].SetBinding(GridViewCell.BackgroundProperty, colorBinding);	    </span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
<span style="color: #b1b100;">End</span> Class</pre></div></div>

<p>4. Add behavior in your XAML (Interaction.Behaviors) tag and HistoryRecordFormatting.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;SLCommonControls:PopUpBase x:Class=&quot;iReferenceSL.frmRFHistory&quot;
xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot; 
xmlns:SLCommonControls=&quot;clr-namespace:SLCommonControls;assembly=SLCommonControls&quot; 
xmlns:controls=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls&quot;
xmlns:telerik=&quot;clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls&quot;
xmlns:telerikGrid=&quot;clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView&quot;
xmlns:telerikData=&quot;clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data&quot;
xmlns:dxm=&quot;clr-namespace:DevExpress.AgMenu;assembly=DevExpress.AgMenu.v8.2&quot;
xmlns:SLCoreConverter=&quot;clr-namespace:SLCoreLib;assembly=SLCoreLib&quot;
xmlns:local=&quot;clr-namespace:iReferenceSL&quot;
xmlns:i=&quot;clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity&quot;
Width=&quot;1000&quot; Height=&quot;800&quot; Title=&quot;History&quot;&gt;
    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;dxm:AgPopupMenu x:Name=&quot;ContextMenuTable&quot; PopupAnimationType=&quot;Scroll&quot;&gt;
            &lt;dxm:AgMenuItem  x:Name=&quot;mnuExport&quot; Header=&quot;Export&quot;&gt;
                &lt;dxm:AgMenuItem.Icon&gt;
                    &lt;Image Source=&quot;Images/Excel.png&quot; Width=&quot;16&quot; Height=&quot;16&quot;/&gt;
                &lt;/dxm:AgMenuItem.Icon&gt;
            &lt;/dxm:AgMenuItem&gt;
        &lt;/dxm:AgPopupMenu&gt;
        &lt;Grid.Resources&gt;
            &lt;SLCoreConverter:TableHistoryColorConverter x:Key=&quot;historyConverter&quot;&gt;&lt;/SLCoreConverter:TableHistoryColorConverter&gt;
        &lt;/Grid.Resources&gt;
        &lt;telerikGrid:RadGridView x:Name=&quot;dgResults&quot; Grid.Row=&quot;1&quot; 
        Grid.Column=&quot;0&quot; AutoGenerateColumns=&quot;False&quot; Exporting=&quot;ExportResults_Exporting&quot;&gt;
            &lt;i:Interaction.Behaviors&gt;
                &lt;local:HistoryRecordFormatting/&gt;
            &lt;/i:Interaction.Behaviors&gt;
        &lt;/telerikGrid:RadGridView&gt;
    &lt;/Grid&gt;
&lt;/SLCommonControls:PopUpBase&gt;</pre></div></div>

<p>Basically what it does is adding the converter on every single cell and use the column name to compare with the changed column. It uses Column.UniqueName to pass it to the ConverterParameter and check whether it&#8217;s on the list of changed column or not. The problem looks simple at the beginning but when it comes to silverlight then it&#8217;s different mechanism of applying the format compared with ASP.NET</p>
<p>The behavior and AssociatedObject_RowLoaded for me looks like itemdatabound event on repeater.</p>
]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/telerik-sl-gridview-cell-foreground-color-dynamically-based-on-multiple-binding/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Numeric textbox with javascript and cross browser compatible</title>
		<link>http://fransiscuss.com/numeric-textbox-with-javascript-and-cross-browser-compatible/</link>
		<comments>http://fransiscuss.com/numeric-textbox-with-javascript-and-cross-browser-compatible/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 06:12:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[numeric textbox]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=254</guid>
		<description><![CDATA[I need to make a text box that does not allow the user to type any numeric key at all

        &#60;asp:TextBox ID=&#34;txtHours&#34; runat=&#34;server&#34; onkeypress=&#34;return fnNumeric_only(event);&#34; MaxLength=&#34;4&#34; CssClass=&#34;txtHours&#34;&#62;&#60;/asp:TextBox&#62;


&#160;
// function to only allow numeric key presses in a textbox
// this doesn't stop pasting of non numeric values
function fnNumeric_only&#40;e&#41; &#123;
  [...]]]></description>
			<content:encoded><![CDATA[<p>I need to make a text box that does not allow the user to type any numeric key at all</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">        &lt;asp:TextBox ID=&quot;txtHours&quot; runat=&quot;server&quot; onkeypress=&quot;return fnNumeric_only(event);&quot; MaxLength=&quot;4&quot; CssClass=&quot;txtHours&quot;&gt;&lt;/asp:TextBox&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// function to only allow numeric key presses in a textbox</span>
<span style="color: #006600; font-style: italic;">// this doesn't stop pasting of non numeric values</span>
<span style="color: #003366; font-weight: bold;">function</span> fnNumeric_only<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// deal with unicode character sets</span>
    <span style="color: #003366; font-weight: bold;">var</span> unicode <span style="color: #339933;">=</span> e.<span style="color: #660066;">charCode</span> <span style="color: #339933;">?</span> e.<span style="color: #660066;">charCode</span> <span style="color: #339933;">:</span> e.<span style="color: #660066;">keyCode</span>;
&nbsp;
    <span style="color: #006600; font-style: italic;">// if the key is backspace, tab, or numeric</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>unicode <span style="color: #339933;">==</span> <span style="color: #CC0000;">8</span> || unicode <span style="color: #339933;">==</span> <span style="color: #CC0000;">9</span> || <span style="color: #009900;">&#40;</span>unicode <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">48</span> <span style="color: #339933;">&amp;&amp;</span> unicode <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">57</span><span style="color: #009900;">&#41;</span> || <span style="color: #009900;">&#40;</span>unicode <span style="color: #339933;">==</span> <span style="color: #CC0000;">46</span> || unicode <span style="color: #339933;">==</span> <span style="color: #CC0000;">44</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// we allow the key press</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// otherwise we don't</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>At the sametime I also need to make the counter/tally changing by the time you start typing or deleting a character from the text box. Let&#8217;s make a scenario this way e.g 3.25 is the text in your textbox and basically what we want is when the user pressing backspace and stop in &#8220;.&#8221; character, you want your function to assume it as &#8220;3&#8243; instead of &#8220;0&#8243;, you can use this function</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> parseLocalNum<span style="color: #009900;">&#40;</span>num<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>num.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I&#8217;ve also added these two function for getting and setting value of an input (e.g textbox and label) which is cross browser compatible</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getControlValue<span style="color: #009900;">&#40;</span>controlName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> controlValue <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> hasInnerText <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerText</span> <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>;
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hasInnerText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        controlValue <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>controlName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerText</span>;
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        controlValue <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>controlName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">textContent</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> controlValue;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> setControlValue<span style="color: #009900;">&#40;</span>controlName<span style="color: #339933;">,</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> controlValue <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> hasInnerText <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerText</span> <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>;
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hasInnerText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>controlName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerText</span> <span style="color: #339933;">=</span> value;
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>controlName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">textContent</span> <span style="color: #339933;">=</span> value;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> controlValue;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>How to use getControlValue or setControlValue</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    setControlValue<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ctl00_ContentPlaceHolder1_lblClaimedHours&quot;</span><span style="color: #339933;">,</span> totalClaimed.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toLocaleString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/numeric-textbox-with-javascript-and-cross-browser-compatible/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reflection GetProperty case sensitive issue</title>
		<link>http://fransiscuss.com/reflection-getproperty-case-sensitive-issue/</link>
		<comments>http://fransiscuss.com/reflection-getproperty-case-sensitive-issue/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 05:49:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Case Sensitive]]></category>

		<category><![CDATA[GetProperty]]></category>

		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=252</guid>
		<description><![CDATA[Reflection on .NET by default is case sensitive for the class member. To make it case insensitive you need to pass BindingFlags.IgnoreCase  . I&#8217;ve passed the ignorecase flag and now it doesn&#8217;t return anything!!!

&#160;
 Dim pi As PropertyInfo = Me.&#91;GetType&#93;&#40;&#41;.GetProperty&#40;fieldname, BindingFlags.IgnoreCase&#41;

Basically, if you pass one flag then the other flags will be overwritten by [...]]]></description>
			<content:encoded><![CDATA[<p>Reflection on .NET by default is case sensitive for the class member. To make it case insensitive you need to pass <em><strong>BindingFlags.IgnoreCase </strong></em> . I&#8217;ve passed the ignorecase flag and now it doesn&#8217;t return anything!!!</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">&nbsp;
 <span style="color: #b1b100;">Dim</span> pi <span style="color: #b1b100;">As</span> PropertyInfo = <span style="color: #b1b100;">Me</span>.<span style="color: #66cc66;">&#91;</span>GetType<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">GetProperty</span><span style="color: #66cc66;">&#40;</span>fieldname, BindingFlags.<span style="color: #66cc66;">IgnoreCase</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Basically, if you pass one flag then the other flags will be overwritten by default which means all the default flags are disappeared. So to make it case insensitive then you need to pass other binding flags</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">&nbsp;
 <span style="color: #b1b100;">Dim</span> pi <span style="color: #b1b100;">As</span> PropertyInfo = <span style="color: #b1b100;">Me</span>.<span style="color: #66cc66;">&#91;</span>GetType<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">GetProperty</span><span style="color: #66cc66;">&#40;</span>fieldname, BindingFlags.<span style="color: #66cc66;">IgnoreCase</span> <span style="color: #b1b100;">Or</span> BindingFlags.<span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Or</span> BindingFlags.<span style="color: #66cc66;">Instance</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/reflection-getproperty-case-sensitive-issue/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Shrink all databases and Set it to Simple in SQL Server</title>
		<link>http://fransiscuss.com/shrink-all-databases-and-set-it-to-simple-in-sql-server/</link>
		<comments>http://fransiscuss.com/shrink-all-databases-and-set-it-to-simple-in-sql-server/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 05:02:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=249</guid>
		<description><![CDATA[Normally, I need to run this script against dev sql server in order for me to free up some space

CREATE TABLE #temp_dbs_table
&#40;
&#91;db_name&#93; sysname NOT NULL PRIMARY KEY,
&#91;mod&#93; tinyint NOT NULL DEFAULT 1
&#41;
&#160;
INSERT INTO #temp_dbs_table ([db_name])
SELECT
name
FROM
master..sysdatabases
WHERE
dbid &#38;gt; 4 --- skip master, tempdb, model and msdb databases
&#160;
declare @db_name sysname
&#160;
SET @db_name = ''
&#160;
while @db_name IS NOT NULL
begin
SET @db_name [...]]]></description>
			<content:encoded><![CDATA[<p>Normally, I need to run this script against dev sql server in order for me to free up some space</p>

<div class="wp_syntax"><div class="code"><pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">#temp_dbs_table</span>
<span style="color: #66cc66;">&#40;</span>
<span style="color: #66cc66;">&#91;</span>db_name<span style="color: #66cc66;">&#93;</span> sysname <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>mod<span style="color: #66cc66;">&#93;</span> tinyint <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #cc66cc;">1</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #808080; font-style: italic;">#temp_dbs_table ([db_name])</span>
<span style="color: #993333; font-weight: bold;">SELECT</span>
name
<span style="color: #993333; font-weight: bold;">FROM</span>
master<span style="color: #66cc66;">..</span>sysdatabases
<span style="color: #993333; font-weight: bold;">WHERE</span>
dbid &amp;gt; <span style="color: #cc66cc;">4</span> <span style="color: #808080; font-style: italic;">--- skip master, tempdb, model and msdb databases</span>
&nbsp;
declare @db_name sysname
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> @db_name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span>
&nbsp;
while @db_name <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
begin
<span style="color: #993333; font-weight: bold;">SET</span> @db_name <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">NULL</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> top <span style="color: #cc66cc;">1</span> @db_name <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#91;</span>db_name<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #808080; font-style: italic;">#temp_dbs_table where [mod] = 1</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">IF</span> @db_name <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span>
break
&nbsp;
print <span style="color: #ff0000;">'--------------------------------------------------'</span>
&nbsp;
print <span style="color: #ff0000;">'&amp;gt; Database: '</span> <span style="color: #66cc66;">+</span> @db_name
&nbsp;
print <span style="color: #ff0000;">'&amp;gt; Changing recovery mode to simple'</span>
&nbsp;
declare @n_cmd nvarchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> @n_cmd <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'alter database ['</span> <span style="color: #66cc66;">+</span> @db_name <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'] set recovery simple'</span>
&nbsp;
exec sp_executesql @n_cmd
&nbsp;
print <span style="color: #ff0000;">'&amp;gt; Shrinking database'</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> @n_cmd <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'dbcc shrinkdatabase(['</span> <span style="color: #66cc66;">+</span> @db_name <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'])'</span>
&nbsp;
exec sp_executesql @n_cmd
&nbsp;
<span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #808080; font-style: italic;">#temp_dbs_table set [mod] = 0 where [db_name] = @db_name</span>
end
&nbsp;
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">#temp_dbs_table</span></pre></div></div>

<p>I got this script from <a href="http://www.sqlservercentral.com/scripts/Backup+%2F+Restore/61952/" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/shrink-all-databases-and-set-it-to-simple-in-sql-server/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Compression in Silverlight Isolated Storage</title>
		<link>http://fransiscuss.com/compression-in-silverlight-isolated-storage/</link>
		<comments>http://fransiscuss.com/compression-in-silverlight-isolated-storage/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 04:34:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Isolated Storage]]></category>

		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=240</guid>
		<description><![CDATA[Isolated storage in silverlight is used to store information or object therefore we don&#8217;t need to go to database to get all the information over and over again but again to use isolated storage or not should be based on case by case. Based on the implementation of the code below, I&#8217;ve found that it [...]]]></description>
			<content:encoded><![CDATA[<p>Isolated storage in silverlight is used to store information or object therefore we don&#8217;t need to go to database to get all the information over and over again but again to use isolated storage or not should be based on case by case. Based on the implementation of the code below, I&#8217;ve found that it can compress the isolated storage file from <strong><span style="color:red">0.8Mb becoming 0.1 MB</span></strong> which is great enough for me since the quota limit is 1 mb and we try not to exceed that limit.</p>
<p>I&#8217;ve got this compression method from <a href="http://www.eggheadcafe.com/tutorials/aspnet/d566463d-83bd-486a-8633-53aa54f405bf/silverlight-2-beta-2-doi.aspx" target="_blank">Peter Bromberg blog</a>. </p>
<p>This compression method is a wrapper to SharpZip Library for Silverlight, you can download it from <a href="" target="_blank">here</a>, you need this library before using the code below. You can download the code below from <a href="" target="_blank">here</a>. </p>
<p>I&#8217;ve also created a Isolated Storage File with the assembly version as the file name to make sure that we have clean isolated storage file assuming the uncompressed version of isolated storage is already in production and we need to clean it up.  <strong>&#8220;AssemblyVersion&#8221;</strong> properties will return the property of the current version no of the running assembly. <strong>CheckIsolatedStorageFileVersion</strong> will make sure that we always have the clean isolated storage for the new assembly.</p>
<p><strong>Sample of usage</strong><br />
<strong>1. How to read/deserialize object from isolated storage</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"> <span style="color: #b1b100;">Dim</span> objMessageCodes <span style="color: #b1b100;">As</span> MessageCodes = GetIsolatedStorage<span style="color: #66cc66;">&#40;</span>Of MessageCodes<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;MyFile.txt&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p><strong>2. How to write/serialize object to isolated storage</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">      <span style="color: #b1b100;">Dim</span> _messageCodes <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MessageCodes<span style="color: #66cc66;">&#40;</span>mListMessage<span style="color: #66cc66;">&#41;</span>
      WriteIsolatedStorage<span style="color: #66cc66;">&#40;</span>_messageCodes, <span style="color: #ff0000;">&quot;myfile.txt&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>These are the definition of the above function to serialize/deserialize object from your silverlight, this function is created based on Generic so it&#8217;s flexible enough to accept anything</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System.<span style="color: #66cc66;">Collections</span>.<span style="color: #66cc66;">Generic</span>
Imports System.<span style="color: #66cc66;">ServiceModel</span>
Imports System.<span style="color: #66cc66;">Threading</span>
Imports System.<span style="color: #66cc66;">IO</span>
Imports System.<span style="color: #66cc66;">IO</span>.<span style="color: #66cc66;">IsolatedStorage</span>
Imports System.<span style="color: #66cc66;">Xml</span>.<span style="color: #66cc66;">Serialization</span>
Imports System.<span style="color: #66cc66;">Runtime</span>.<span style="color: #66cc66;">Serialization</span>
Imports System.<span style="color: #66cc66;">Reflection</span>
&nbsp;
<span style="color: #b1b100;">Public</span> Class MySL
 <span style="color: #b1b100;">Private</span> mAppStorage <span style="color: #b1b100;">As</span> IsolatedStorageFile
&nbsp;
    <span style="color: #808080;">''' &lt;summary&gt;</span>
    <span style="color: #808080;">''' This is used to write the compressed object to Isolated Storage</span>
    <span style="color: #808080;">''' &lt;/summary&gt;</span>
    <span style="color: #808080;">''' &lt;param name=&quot;filename&quot;&gt;&lt;/param&gt;</span>
    <span style="color: #808080;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> WriteIsolatedStorage<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal obj <span style="color: #b1b100;">As</span> T, ByVal filename <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#41;</span>
        Try
            <span style="color: #b1b100;">Dim</span> xmlByte <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = Compression.<span style="color: #66cc66;">SerializeAndCompress</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>
&nbsp;
            Using _stream <span style="color: #b1b100;">As</span> IsolatedStorageFileStream = mAppStorage.<span style="color: #66cc66;">CreateFile</span><span style="color: #66cc66;">&#40;</span>filename<span style="color: #66cc66;">&#41;</span>
                _stream.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>xmlByte, 0, xmlByte.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
        Catch ex <span style="color: #b1b100;">As</span> Exception
            Throw ex
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
&nbsp;
    <span style="color: #808080;">''' &lt;summary&gt;</span>
    <span style="color: #808080;">''' this is used get the compressed object from Isolated storage</span>
    <span style="color: #808080;">''' &lt;/summary&gt;</span>
    <span style="color: #808080;">''' &lt;typeparam name=&quot;T&quot;&gt;&lt;/typeparam&gt;</span>
    <span style="color: #808080;">''' &lt;param name=&quot;fileName&quot;&gt;&lt;/param&gt;</span>
    <span style="color: #808080;">''' &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #808080;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Function</span> GetIsolatedStorage<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal fileName <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> T
        Try
            Using _stream <span style="color: #b1b100;">As</span> IsolatedStorageFileStream = mAppStorage.<span style="color: #66cc66;">OpenFile</span><span style="color: #66cc66;">&#40;</span>fileName, FileMode.<span style="color: #b1b100;">Open</span><span style="color: #66cc66;">&#41;</span>
                Using _reader <span style="color: #b1b100;">As</span> BinaryReader = <span style="color: #b1b100;">New</span> BinaryReader<span style="color: #66cc66;">&#40;</span>_stream<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">Dim</span> tmpBytes <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">ReDim</span> tmpBytes<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">Dim</span> fullBytes <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #b1b100;">Nothing</span>
                    <span style="color: #b1b100;">Dim</span> xmlStream <span style="color: #b1b100;">As</span> MemoryStream = <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                    <span style="color: #b1b100;">While</span> <span style="color: #b1b100;">True</span>
                        <span style="color: #b1b100;">Dim</span> read <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = _reader.<span style="color: #66cc66;">Read</span><span style="color: #66cc66;">&#40;</span>tmpBytes, 0, tmpBytes.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>read &lt;= 0<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                            fullBytes = xmlStream.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                            <span style="color: #b1b100;">Exit</span> <span style="color: #b1b100;">While</span>
                        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
                        xmlStream.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>tmpBytes, 0, read<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">While</span>
&nbsp;
                    <span style="color: #b1b100;">Dim</span> xmlTempbyte <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = xmlStream.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                     <span style="color: #b1b100;">Return</span> Compression.<span style="color: #66cc66;">DecompressAndDeserialize</span><span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>xmlTempbyte<span style="color: #66cc66;">&#41;</span>
                <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> <span style="color: #b1b100;">Nothing</span>
&nbsp;
        Catch ex <span style="color: #b1b100;">As</span> Exception
            Throw ex
        <span style="color: #b1b100;">End</span> Try
&nbsp;
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
<span style="color: #b1b100;">Private</span> _compression <span style="color: #b1b100;">As</span> Compression = <span style="color: #b1b100;">Nothing</span>
&nbsp;
    <span style="color: #b1b100;">Private</span> ReadOnly <span style="color: #b1b100;">Property</span> Compression<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Compression
        <span style="color: #b1b100;">Get</span>
            <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>_compression Is <span style="color: #b1b100;">Nothing</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                _compression = <span style="color: #b1b100;">New</span> Compression<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
            <span style="color: #b1b100;">Return</span> _compression
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Get</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Property</span>
&nbsp;
    <span style="color: #808080;">''' &lt;summary&gt;</span>
    <span style="color: #808080;">''' get the assembly version</span>
    <span style="color: #808080;">''' &lt;/summary&gt;</span>
    <span style="color: #808080;">''' &lt;value&gt;&lt;/value&gt;</span>
    <span style="color: #808080;">''' &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #808080;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #b1b100;">Private</span> ReadOnly <span style="color: #b1b100;">Property</span> AssemblyVersion<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span>
        <span style="color: #b1b100;">Get</span>
            <span style="color: #b1b100;">Dim</span> <span style="color: #b1b100;">name</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = Assembly.<span style="color: #66cc66;">GetExecutingAssembly</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">FullName</span>
            <span style="color: #b1b100;">Dim</span> asmName <span style="color: #b1b100;">As</span> AssemblyName = <span style="color: #b1b100;">New</span> AssemblyName<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">name</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Return</span> asmName.<span style="color: #66cc66;">Version</span>.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">Replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span>, <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Get</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Property</span>
&nbsp;
<span style="color: #808080;">''' &lt;summary&gt;</span>
    <span style="color: #808080;">''' try to clear isolated storage</span>
    <span style="color: #808080;">''' &lt;/summary&gt;</span>
    <span style="color: #808080;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> CheckIsolatedStorageFileVersion<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        Try
            <span style="color: #b1b100;">Dim</span> isoStorage <span style="color: #b1b100;">As</span> IsolatedStorageFile = IsolatedStorageFile.<span style="color: #66cc66;">GetUserStoreForSite</span>
&nbsp;
            <span style="color: #b1b100;">If</span> <span style="color: #b1b100;">Not</span> mAppStorage.<span style="color: #66cc66;">FileExists</span><span style="color: #66cc66;">&#40;</span>AssemblyVersion + <span style="color: #ff0000;">&quot;.txt&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                <span style="color: #808080;">'clear all the isolated storage</span>
                isoStorage.<span style="color: #66cc66;">Remove</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                mAppStorage.<span style="color: #66cc66;">Remove</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                mAppStorage = IsolatedStorageFile.<span style="color: #66cc66;">GetUserStoreForApplication</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                Using _stream <span style="color: #b1b100;">As</span> IsolatedStorageFileStream = mAppStorage.<span style="color: #66cc66;">CreateFile</span><span style="color: #66cc66;">&#40;</span>AssemblyVersion + <span style="color: #ff0000;">&quot;.txt&quot;</span><span style="color: #66cc66;">&#41;</span>
                    Using sw <span style="color: #b1b100;">As</span> StreamWriter = <span style="color: #b1b100;">New</span> StreamWriter<span style="color: #66cc66;">&#40;</span>_stream<span style="color: #66cc66;">&#41;</span>
                        sw.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>AssemblyVersion<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">End</span> Using
                <span style="color: #b1b100;">End</span> Using
                <span style="color: #808080;">'Throw New Exception(&quot;Clearing!!!&quot;)</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
        Catch ex <span style="color: #b1b100;">As</span> Exception
            Throw ex
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
&nbsp;
<span style="color: #b1b100;">End</span> Class</pre></div></div>

<p><strong>Wrapper Class to SL SharpZipLib</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System
Imports System.<span style="color: #66cc66;">Text</span>
Imports System.<span style="color: #66cc66;">IO</span>
Imports System.<span style="color: #66cc66;">Collections</span>
Imports System.<span style="color: #66cc66;">Diagnostics</span>
Imports System.<span style="color: #66cc66;">Collections</span>.<span style="color: #66cc66;">Generic</span>
Imports System.<span style="color: #66cc66;">Runtime</span>.<span style="color: #66cc66;">Serialization</span>
Imports ICSharpCode.<span style="color: #66cc66;">SharpZipLib</span>.<span style="color: #66cc66;">Zip</span>.<span style="color: #66cc66;">Compression</span>
Imports System.<span style="color: #66cc66;">Xml</span>.<span style="color: #66cc66;">Serialization</span>
Imports System.<span style="color: #66cc66;">Text</span>.<span style="color: #66cc66;">RegularExpressions</span>
&nbsp;
<span style="color: #b1b100;">Public</span> Class Compression
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Sub</span> <span style="color: #b1b100;">New</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Serialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal inst <span style="color: #b1b100;">As</span> T<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Dim</span> dcs <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> DataContractSerializer<span style="color: #66cc66;">&#40;</span>GetType<span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        Using ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream
            dcs.<span style="color: #66cc66;">WriteObject</span><span style="color: #66cc66;">&#40;</span>ms, inst<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Return</span> ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> Using
&nbsp;
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Deserialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal objectData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> T
        <span style="color: #b1b100;">Dim</span> dcs <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> DataContractSerializer<span style="color: #66cc66;">&#40;</span>GetType<span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        Using ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span>objectData<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Return</span> CType<span style="color: #66cc66;">&#40;</span>dcs.<span style="color: #66cc66;">ReadObject</span><span style="color: #66cc66;">&#40;</span>ms<span style="color: #66cc66;">&#41;</span>, T<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> Using
&nbsp;
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> SerializeAndCompress<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal inst <span style="color: #b1b100;">As</span> T<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Dim</span> b <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = Serialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>inst<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Return</span> Compress<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> DecompressAndDeserialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal bytData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> T
        <span style="color: #b1b100;">Dim</span> bytes <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = Decompress<span style="color: #66cc66;">&#40;</span>bytData<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Return</span> Deserialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>bytes<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Compress<span style="color: #66cc66;">&#40;</span>ByVal strInput <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        Try
            <span style="color: #b1b100;">Dim</span> bytData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = System.<span style="color: #66cc66;">Text</span>.<span style="color: #66cc66;">Encoding</span>.<span style="color: #66cc66;">UTF8</span>.<span style="color: #66cc66;">GetBytes</span><span style="color: #66cc66;">&#40;</span>strInput<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> defl <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> Deflater<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span>, <span style="color: #b1b100;">False</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            Using s <span style="color: #b1b100;">As</span> Stream = <span style="color: #b1b100;">New</span> Streams.<span style="color: #66cc66;">DeflaterOutputStream</span><span style="color: #66cc66;">&#40;</span>ms, defl<span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>bytData, 0, bytData.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> DirectCast<span style="color: #66cc66;">&#40;</span>ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        Catch
            Throw
&nbsp;
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Compress<span style="color: #66cc66;">&#40;</span>ByVal bytData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        Try
&nbsp;
            <span style="color: #b1b100;">Dim</span> ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> defl <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> Deflater<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span>, <span style="color: #b1b100;">False</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            Using s <span style="color: #b1b100;">As</span> Stream = <span style="color: #b1b100;">New</span> Streams.<span style="color: #66cc66;">DeflaterOutputStream</span><span style="color: #66cc66;">&#40;</span>ms, defl<span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>bytData, 0, bytData.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> DirectCast<span style="color: #66cc66;">&#40;</span>ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        Catch
            Throw
&nbsp;
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Compress<span style="color: #66cc66;">&#40;</span>ByVal bytData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, ByVal ParamArray ratio <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        <span style="color: #b1b100;">Dim</span> compRatio <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = <span style="color: #cc66cc;">9</span>
        Try
            <span style="color: #b1b100;">If</span> ratio<span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">&#41;</span> &gt; 0 <span style="color: #b1b100;">Then</span>
                compRatio = ratio<span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
        Catch
&nbsp;
        <span style="color: #b1b100;">End</span> Try
&nbsp;
        Try
            <span style="color: #b1b100;">Dim</span> ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> defl <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> Deflater<span style="color: #66cc66;">&#40;</span>compRatio, <span style="color: #b1b100;">False</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            Using s <span style="color: #b1b100;">As</span> Stream = <span style="color: #b1b100;">New</span> Streams.<span style="color: #66cc66;">DeflaterOutputStream</span><span style="color: #66cc66;">&#40;</span>ms, defl<span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>bytData, 0, bytData.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> DirectCast<span style="color: #66cc66;">&#40;</span>ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        Catch
            Throw
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Decompress<span style="color: #66cc66;">&#40;</span>ByVal bytInput <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        Try
&nbsp;
            <span style="color: #b1b100;">Dim</span> ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span>bytInput, 0, bytInput.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> bytResult <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #b1b100;">Nothing</span>
            <span style="color: #b1b100;">Dim</span> strResult <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #66cc66;">Empty</span>
            <span style="color: #b1b100;">Dim</span> writeData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #b1b100;">New</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4095</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
&nbsp;
            Using s2 <span style="color: #b1b100;">As</span> Stream = <span style="color: #b1b100;">New</span> Streams.<span style="color: #66cc66;">InflaterInputStream</span><span style="color: #66cc66;">&#40;</span>ms<span style="color: #66cc66;">&#41;</span>
                bytResult = ReadFullStream<span style="color: #66cc66;">&#40;</span>s2<span style="color: #66cc66;">&#41;</span>
                s2.<span style="color: #b1b100;">Close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> bytResult
        Catch
            Throw
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> ReadFullStream<span style="color: #66cc66;">&#40;</span>ByVal stream <span style="color: #b1b100;">As</span> Stream<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Dim</span> buffer <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #b1b100;">New</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32767</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
        Using ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">While</span> <span style="color: #b1b100;">True</span>
                <span style="color: #b1b100;">Dim</span> read <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = stream.<span style="color: #66cc66;">Read</span><span style="color: #66cc66;">&#40;</span>buffer, 0, buffer.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #b1b100;">If</span> read &lt;= 0 <span style="color: #b1b100;">Then</span>
                    <span style="color: #b1b100;">Return</span> ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
                ms.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>buffer, 0, read<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">While</span>
        <span style="color: #b1b100;">End</span> Using
&nbsp;
        <span style="color: #b1b100;">Return</span> buffer
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
<span style="color: #b1b100;">End</span> Class</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/compression-in-silverlight-isolated-storage/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
