<?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>Dreams will remain dreams until you stop dreaming and start working</title>
	<atom:link href="http://www.asim.com.np/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.asim.com.np</link>
	<description>Sharing my xperiences</description>
	<pubDate>Wed, 30 Sep 2009 04:36:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Changing BackColor of Each Cell of a GridView</title>
		<link>http://www.asim.com.np/?p=6</link>
		<comments>http://www.asim.com.np/?p=6#comments</comments>
		<pubDate>Tue, 01 Jul 2008 12:23:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.asim.com.np/?p=6</guid>
		<description><![CDATA[This article is about formatting the cells of a gridview. Imagine you have to change backcolor of a paticular cell in the grid view  conditionally. How would you do it? Below is the Solution for this.
Suppose you have to compare the value of a paticular cell with date field which comes from the database. Lets keep the date [...]]]></description>
			<content:encoded><![CDATA[<p>This article is about formatting the cells of a gridview. Imagine you have to change backcolor of a paticular cell in the grid view  conditionally. How would you do it? Below is the Solution for this.</p>
<p>Suppose you have to compare the value of a paticular cell with date field which comes from the database. Lets keep the date field in a variablesi,e.<br />
<span style="font-size: x-small;"> CDateVariable = </span><span style="color: #0000ff; font-size: x-small;">CDate</span><span style="font-size: x-small;">(ds.Tables(1).Rows(0)(</span><span style="color: #800000; font-size: x-small;">&#8220;DateFromDatabase&#8221;</span><span style="font-size: x-small;">))<br />
<span style="font-size: x-small;"><br />
Keep the value in  the cell that u want to compare in a label control. Then check for the control in  the code behind in this way:<br />
</span><span style="color: #0000ff; font-size: x-small;">If</span><span style="font-size: x-small;"> e.Row.RowType = DataControlRowType.DataRow </span><span style="color: #0000ff; font-size: x-small;">Then<br />
Now Define a label variable in code behind<br />
</span></span><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">Dim</span><span style="font-size: x-small;"> lbl </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> Label<br />
Now by using findcontrol attribute, assign the value of the label control in the cell to the variable &#8216; lbl &#8216; .<br />
lbl = </span><span style="color: #0000ff; font-size: x-small;">CType</span><span style="font-size: x-small;">(e.Row.Cells(10).FindControl(</span><span style="color: #800000; font-size: x-small;">&#8220;lblLastCorpReview&#8221;</span><span style="font-size: x-small;">), Label)<br />
Check wether the value in the label control is blank or not.<br />
</span><span style="color: #0000ff; font-size: x-small;"> If</span><span style="font-size: x-small;"> lbl.Text &lt;&gt; </span><span style="color: #800000; font-size: x-small;">&#8220;&#8221;</span><span style="font-size: x-small;"> <span style="color: #0000ff;">Then</span><br />
After that as we are comparing the date variable change the data type of the value in the label control to date in this fashion:<br />
</span><span style="font-size: x-small;">tLastCorpReview = </span><span style="color: #0000ff; font-size: x-small;">CDate</span><span style="font-size: x-small;">(lbl.Text)<br />
Now compare the date ( or any condition you want):<br />
</span><span style="color: #0000ff; font-size: x-small;"> If</span><span style="font-size: x-small;"> (DateTime.Compare(tLastCorpReview, <span style="color: #800000;">DateFromDatabase</span>)) &lt; 0 </span><span style="color: #0000ff; font-size: x-small;">Then<br />
If the condition is true ( or false accordin to your bussiness logic) change the color of the cell using line below:(<span style="font-size: 10pt; font-family: Verdana; color: #000000;">‘ changing the color of 10<sup>th</sup> cell of each row</span></span></span><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">)<br />
</span><span style="font-size: x-small;">e.Row.Cells(10).BackColor = System.Drawing.ColorTranslator.FromHtml(</span><span style="color: #800000; font-size: x-small;">&#8220;#FFFFE6&#8243;</span><span style="font-size: x-small;">)<br />
</span><span style="color: #0000ff; font-size: x-small;"> End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If<br />
</span><span style="color: #0000ff; font-size: x-small;"> End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If<br />
</span><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></span></p>
<div><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">Now the  total codes will be :<br />
<span style="color: #0000ff; font-size: x-small;"><br />
If</span><span style="font-size: x-small;"> e.Row.RowType = DataControlRowType.DataRow </span><span style="color: #0000ff; font-size: x-small;">Then</span><br />
</span></span><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="font-size: x-small;"><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">Dim</span><span style="font-size: x-small;"> lbl </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> Label<br />
lbl = </span><span style="color: #0000ff; font-size: x-small;">CType</span><span style="font-size: x-small;">(e.Row.Cells(10).FindControl(</span><span style="color: #800000; font-size: x-small;">&#8220;lblDateFromDatabase&#8221;</span></span></span><span style="font-size: x-small;">), Label)</span></p>
<div><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="font-size: x-small;"><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"> If</span><span style="font-size: x-small;"> lbl.Text &lt;&gt; </span><span style="color: #800000; font-size: x-small;">&#8220;&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Then<br />
</span><span style="font-size: x-small;">celldate= </span><span style="color: #0000ff; font-size: x-small;">CDate</span><span style="font-size: x-small;">(lbl.Text)<br />
</span><span style="color: #0000ff; font-size: x-small;">If</span><span style="font-size: x-small;"> (DateTime.Compare(celldate, <span style="font-size: 10pt; font-family: Verdana; color: #000000;">CDateVariable</span>)) &lt; 0 </span><span style="color: #0000ff; font-size: x-small;">Then<br />
</span><span style="font-size: x-small;">e.Row.Cells(10).BackColor = System.Drawing.ColorTranslator.FromHtml(</span><span style="color: #800000; font-size: x-small;">&#8220;#FFFFE6&#8243;</span><span style="font-size: x-small;">)<br />
</span><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If<br />
</span><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If<br />
</span><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></p>
<p></span></span></span></span></div>
<p></span><span style="font-size: x-small;"></p>
<p></span></p>
<p></span></div>
<div><span style="font-size: x-small;"></p>
<div><span style="font-size: x-small;"> </span></div>
<p></span></div>
<div><span style="font-size: x-small;"><span style="font-size: x-small;"><br />
</span></span></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.asim.com.np/?feed=rss2&amp;p=6</wfw:commentRss>
		</item>
		<item>
		<title>SQL Injections-Unexpectedly Dangerous. What?How?</title>
		<link>http://www.asim.com.np/?p=4</link>
		<comments>http://www.asim.com.np/?p=4#comments</comments>
		<pubDate>Sun, 01 Jun 2008 09:40:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.asim.com.np/?p=4</guid>
		<description><![CDATA[Not all the user inputs are safe. Some of the inputs can be very hazardous to your website because it can lead to SQL injections.
SQL injections  are those scripts/queries formed by the concatenation of dynamic sql queries you write and the input users give.
lets take an example to be clear on it. Suppose you [...]]]></description>
			<content:encoded><![CDATA[<p>Not all the user inputs are safe. Some of the inputs can be very hazardous to your website because it can lead to SQL injections.<br />
SQL injections  are those scripts/queries formed by the concatenation of dynamic sql queries you write and the input users give.<br />
lets take an example to be clear on it. Suppose you have written following scripts for your application:<br />
Dim empID as String<br />
Dim SqlQuery as String</p>
<p>empID  = Request.QueryString(&#8221;emp_id&#8221;)<br />
SqlQuery=&#8221;SELECT emp_Name FROM employee WHERE emp_id= &#8216; &#8221; + empID  + “ ‘ “<br />
Now, if user clicks or inputs something to get the name of enployee, then he will get it. Like he can input the emp_id as 5 . But there’s no guarantee that all users will input just a number or what the programmer expects them to input. Just think what happens if  any user unintentionally or a hacker intentionally inputs this :’ 5 ; DROP TABLE employee &#8212;‘ . What this does is it terminates the current statement with semicolon ( ; ) i.e, it terminates SELECT emp_name FROM employee WHERE emp_id=5 . And then another statement starts i.e, DROP TABLE employee . After that the ‘ &#8212; ‘ at last comments out everything after that.<br />
This creates an SQL injection and can leave u completely breathless. Not only dropping the tables but hackers can even perform a join and retrieve all your data.<br />
Now lets move into the solution for SQL injection.<br />
1.	Don’t use dynamic SQL statements.  Even if you want to use , then use only with type-safe parameter encoding. Like done below</p>
<p>Dim empID AS String<br />
Dim cmd AS New SqlCommand<br />
Dim param AS New SqlParameter<br />
empID=Request.QueryString ( “emp_id”)<br />
cmd= “SELECT emp_Name FROM employee WHERE emp_id= @ empID<br />
param((“empID”, SqlDbType.VarChar)<br />
cmd.Parameters.Add(param)</p>
<p>2.	Use stored procedures always as far as possible.<br />
Conduct Security Review.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.asim.com.np/?feed=rss2&amp;p=4</wfw:commentRss>
		</item>
		<item>
		<title>Copying files from one folder to another using php</title>
		<link>http://www.asim.com.np/?p=3</link>
		<comments>http://www.asim.com.np/?p=3#comments</comments>
		<pubDate>Mon, 28 Apr 2008 18:49:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.asim.com.np/?p=3</guid>
		<description><![CDATA[As a part of my work i had to do this task. The complete task assigned was to copy the file from the folder &#8216;images&#8217; to a new folder &#8217;tiles&#8217; and the the name of the files copied had to be the concatenation of two columns in the table in the database.
Slolution :
&#60;!DOCTYPE html PUBLIC [...]]]></description>
			<content:encoded><![CDATA[<p>As a part of my work i had to do this task. The complete task assigned was to copy the file from the folder &#8216;images&#8217; to a new folder &#8217;tiles&#8217; and the the name of the files copied had to be the concatenation of two columns in the table in the database.</p>
<p>Slolution :</p>
<p>&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&#8220;&gt;<br />
&lt;html xmlns=&#8221;<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>&#8220;&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=utf-8&#8243; /&gt;<br />
&lt;title&gt;Untitled Document&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;?php</p>
<p>//connect to the database<br />
 $user_name=&#8221;root&#8221;;<br />
 $password=&#8221;password&#8221;;<br />
 $database=&#8221;database_name&#8221;;<br />
 $server=&#8221;localhost&#8221;;<br />
 <br />
 $db_handle=mysql_connect($server,$user_name,$password);<br />
 $dbfound=mysql_select_db($database);<br />
 <br />
 if($dbfound)<br />
 {<br />
  echo &#8220;connected to database &lt;br&gt;&#8221;;<br />
  $sql = &#8220;write the sql statement here&#8221;;<br />
  $result = mysql_query($sql);</p>
<p>  while ($row = mysql_fetch_row($result)) {<br />
   // check if file exists<br />
   if file_exists(row['image'])<br />
   {<br />
    //copy the file</p>
<p>$source=&#8217;$_SERVER['DOCUMENT_ROOT'].&#8221;/images/&#8221;.row['image']&#8216;;<br />
$destination=&#8217;$_SERVER['DOCUMENT_ROOT'].&#8221;/tiles/&#8221;.row['products_style_code'].&#8221; - &#8220;.row['products_name'].&#8221;.jpg&#8217;</p>
<p>copy($source,$destination);   <br />
   }<br />
  }<br />
 }<br />
 else<br />
 {<br />
  echo &#8220;cannot connect to the database&#8221;;<br />
 }<br />
?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.asim.com.np/?feed=rss2&amp;p=3</wfw:commentRss>
		</item>
	</channel>
</rss>
