<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"><id>tag:blogger.com,1999:blog-6837250508009744375</id><updated>2009-11-11T23:15:05.127+05:00</updated><title type="text">Visual Basic Development Issues</title><subtitle type="html">This blog helps and discusses issues regarding Development in Visual Basic 2005 Programming Language. Whether you are a novice or an expert developer you may find a new idea with each post.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://arsalantamiz.blogspot.com/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default?start-index=26&amp;max-results=25" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>85</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><link rel="self" href="http://feeds.feedburner.com/VisualBasicDevelopmentIssues" type="application/atom+xml" /><feedburner:emailServiceId>VisualBasicDevelopmentIssues</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-8523234755262582924</id><published>2009-09-24T12:24:00.003+06:00</published><updated>2009-09-24T12:43:22.056+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Useful Links" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005" /><title type="text">Useful Links for SQL Server</title><content type="html">Stuck while manually inserting values in an Identity column? Here is what you need to do &lt;a href="http://www.sqlteam.com/article/how-to-insert-values-into-an-identity-column-in-sql-server"&gt;How to Insert Values into an Identity Column in SQL Server&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is a great topic for beginners to learn about the Execution Plans in SQL Server &lt;a href="http://www.sqlservercentral.com/articles/Administration/executionplans/1345/"&gt;Beginners topic for understanding Execution Plans in SQL Server&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Is your SQL Server eating your CPU too much? Don't know which Query or Stored Procedure is behind this? A must have tool for SQL Server &lt;a href="http://www.sql-server-performance.com/articles/per/bm_performance_dashboard_2005_p1.aspx"&gt;Making the Most Out of the SQL Server 2005 Performance Dashboard&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Are you an advanced SQL Server 2005 Programmer? Do you know about CROSS APPLY? &lt;a href="http://www.sqlteam.com/article/using-cross-apply-in-sql-server-2005"&gt;Using CROSS APPLY in SQL Server 2005&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-8523234755262582924?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/utwVwmKJejnN-X4ShhFXQszc5_0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/utwVwmKJejnN-X4ShhFXQszc5_0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/utwVwmKJejnN-X4ShhFXQszc5_0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/utwVwmKJejnN-X4ShhFXQszc5_0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/0qzJ1uUppX0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/8523234755262582924/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=8523234755262582924" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/8523234755262582924" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/8523234755262582924" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/0qzJ1uUppX0/useful-links-for-sql-server.html" title="Useful Links for SQL Server" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2009/09/useful-links-for-sql-server.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-6697671469924420785</id><published>2009-05-07T16:15:00.003+06:00</published><updated>2009-05-07T16:43:35.909+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Web Development" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005" /><title type="text">Importing IIS Web Log into SQL Server 2005</title><content type="html">Today I was trying to import the IIS log of my Web Server into SQL Server 2005 Database (for further analyses). So first I started googling about it and found this link,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://support.microsoft.com/kb/296085"&gt;How To Use SQL Server to Analyze Web Logs&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Very useful article BUT this one is old maybe because the table have different schema. By the way I have IIS 6.0 on my web server. So I did some workarounds and successfully imported the Log. Now I am posting here in case someone might be trying to do the same thing.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step #1: Create a table in Database&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color:blue"&gt;CREATE TABLE&lt;/span&gt; [dbo].[IISLog](&lt;br /&gt; [date] [datetime] &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [time] [datetime] &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [site-name] [varchar](255) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [s-computername] [varchar](255) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [s-ip] [varchar](50) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [cs-uri-stem] [varchar](255) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [cs-uri-query] [varchar](2048) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [c-ip] [varchar](50) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [cs(User-Agent)] [varchar](2048) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [cs(Cookie)] [varchar](2048) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [cs(Referer)] [varchar](2048) &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [sc-status] [int] &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [sc-bytes] [int] &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [cs-bytes] [int] &lt;span style="color:gray"&gt;NULL&lt;/span&gt;,&lt;br /&gt; [time-taken] [int] &lt;span style="color:gray"&gt;NULL&lt;/span&gt;&lt;br /&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step #2: Prepare the Log file (since it contains some description lines on top)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;So this is a tricky step. As the Log file contains some description lines on top starting with "#" sign. Therefore SQL Server will NOT be able to import it. One more thing is that these log files can be large (or very large). The Log file I had was  of size aprox. 216 MB. So obviously we cannot open it in NotePad etc.&lt;br /&gt;&lt;br /&gt;The same article provides a small utility which removes the line, but I think there is bug in this utility, cause it is limiting file upto 43 MB. So I decided to write my own version.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://cid-c23746227866488d.skydrive.live.com/self.aspx/Public/PrepIISLogFileForImport.zip"&gt;PrepIISLogFileForImport.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;As I started to create this application for IIS Log import but then it ends up with a generic utility. Which actually displays the text file content and have an option to skip number of lines from start. Therefore we can use it as,&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:10px;font-size:80%;background-color:black;color:white;"&gt;C:\&gt;PrepIISLogFileForImport C:\LogFile.Log skip=4 &gt;newlogfile.txt&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step #3: Bulk import the Log file into SQL Server Table&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Hence the final step is to import the log file in the same table. Which can be done by,&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color:blue"&gt;BULK INSERT&lt;/span&gt; [dbo].[IISLog] &lt;span style="color:blue"&gt;FROM&lt;/span&gt; &lt;span style="color:red"&gt;'C:\newlogfile.txt'&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue"&gt;WITH&lt;/span&gt; (&lt;br /&gt;    &lt;span style="color:blue"&gt;FIELDTERMINATOR&lt;/span&gt; = &lt;span style="color:red"&gt;' '&lt;/span&gt;,&lt;br /&gt;    &lt;span style="color:blue"&gt;ROWTERMINATOR&lt;/span&gt; = &lt;span style="color:red"&gt;'\n'&lt;/span&gt;&lt;br /&gt;)&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-6697671469924420785?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5n44vsWIfv4CudKoWxust2LKt5s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5n44vsWIfv4CudKoWxust2LKt5s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5n44vsWIfv4CudKoWxust2LKt5s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5n44vsWIfv4CudKoWxust2LKt5s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/fME-7cYYGQo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/6697671469924420785/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=6697671469924420785" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/6697671469924420785" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/6697671469924420785" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/fME-7cYYGQo/importing-iis-web-log-into-sql-server.html" title="Importing IIS Web Log into SQL Server 2005" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2009/05/importing-iis-web-log-into-sql-server.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-3948590518106362624</id><published>2009-03-09T16:24:00.009+05:00</published><updated>2009-03-09T23:19:57.931+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Useful Functions" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Functions" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005" /><title type="text">SQL Server Date Time Useful Functions</title><content type="html">&lt;a id="sqldatetimetop"&gt;&lt;/a&gt;Here are some SQL Server Date Time Useful functions.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;&lt;a href="#datecreate"&gt;DateCreate&lt;/a&gt;&lt;/strong&gt; - Creates Date through Year, Month and Day&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a href="#datetostrshort"&gt;DateToStrShort&lt;/a&gt;&lt;/strong&gt; - Accepts Date and returns as '1-Jan-2009'&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a href="#dategetdaysinmonth"&gt;DateGetDaysInMonth&lt;/a&gt;&lt;/strong&gt; - Accepts Month and Year and returns number of days in month&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a href="#dategettimeonly"&gt;DateGetTimeOnly&lt;/a&gt;&lt;/strong&gt; - Accepts date and returns time as '10:33 PM'&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a href="#dategetdateonly"&gt;DateGetDateOnly&lt;/a&gt;&lt;/strong&gt; - Accepts Date and convert it into Date only i.e. removes the Time Part&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a href="#dategetmonthfirstdate"&gt;DateGetMonthFirstDate&lt;/a&gt;&lt;/strong&gt; - Gets the first date of Month&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a href="#dategetmonthlastdate"&gt;DateGetMonthLastDate&lt;/a&gt;&lt;/strong&gt; - Gets the last date of Month&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a href="#dategetmonthname"&gt;DateGetMonthName&lt;/a&gt;&lt;/strong&gt; - Gets the Month Name&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Review the functions below or &lt;a href="http://cid-c23746227866488d.skydrive.live.com/self.aspx/Public/UsefulDateTimeFunctions.sql"&gt;download&lt;/a&gt; the SQL file.&lt;br /&gt;&lt;br /&gt;&lt;a id="datecreate"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;font color="green"&gt;-- =============================================&lt;br /&gt;-- Author:        Arsalan Tamiz&lt;br /&gt;-- Description:   This function accepts Year, Month and Day&lt;br /&gt;--                and returns Date&lt;br /&gt;-- =============================================&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;CREATE FUNCTION&lt;/font&gt; [DateCreate]&lt;br /&gt;(&lt;br /&gt;    @Year &lt;font color="blue"&gt;int&lt;/font&gt;,&lt;br /&gt;    @Month &lt;font color="blue"&gt;int&lt;/font&gt;,&lt;br /&gt;    @Day &lt;font color="blue"&gt;int&lt;/font&gt;&lt;br /&gt;)&lt;br /&gt;&lt;font color="blue"&gt;RETURNS datetime&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;/font&gt;&lt;br /&gt;    &lt;font color="green"&gt;-- Declare the return variable here&lt;/font&gt;&lt;br /&gt;    &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Result &lt;font color="blue"&gt;datetime&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;font color="green"&gt;-- Add the T-SQL statements to compute the return value here&lt;/font&gt;&lt;br /&gt;    &lt;font color="blue"&gt;SET&lt;/font&gt; @Result = &lt;font color="magenta"&gt;CAST&lt;/font&gt;    (&lt;br /&gt;                            &lt;font color="magenta"&gt;CAST&lt;/font&gt;(@Year &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(10)) + &lt;font color="red"&gt;'-'&lt;/font&gt; +&lt;br /&gt;                            &lt;font color="magenta"&gt;CAST&lt;/font&gt;(@Month &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(2)) + &lt;font color="red"&gt;'-'&lt;/font&gt; + &lt;br /&gt;                            &lt;font color="magenta"&gt;CAST&lt;/font&gt;(@Day &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(2))&lt;br /&gt;                            &lt;font color="blue"&gt;AS datetime&lt;/font&gt;&lt;br /&gt;                          );&lt;br /&gt;&lt;br /&gt;    &lt;font color="green"&gt;-- Return the result of the function&lt;/font&gt;&lt;br /&gt;    &lt;font color="blue"&gt;RETURN&lt;/font&gt; @Result;&lt;br /&gt;&lt;font color="blue"&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;div style="text-align:right;"&gt;&lt;a href="#sqldatetimetop"&gt;Back to Top&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;a id="datetostrshort"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;font color="green"&gt;-- =============================================&lt;br /&gt;-- Author:        Arsalan Tamiz&lt;br /&gt;-- Description:   This function converts the given&lt;br /&gt;--                date in to string. Useful function&lt;br /&gt;--                for displaying date as '10-Jan-2009' for example&lt;br /&gt;-- =============================================&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;CREATE FUNCTION&lt;/font&gt; [DateToStrShort] &lt;br /&gt;(&lt;br /&gt;    &lt;font color="green"&gt;-- Add the parameters for the function here&lt;/font&gt;&lt;br /&gt;    @DateToConvert &lt;font color="blue"&gt;datetime&lt;/font&gt;&lt;br /&gt;)&lt;br /&gt;&lt;font color="blue"&gt;RETURNS varchar&lt;/font&gt;(50)&lt;br /&gt;&lt;font color="blue"&gt;AS&lt;br /&gt;BEGIN&lt;/font&gt;&lt;br /&gt;    &lt;font color="green"&gt;-- Declare the return variable here&lt;/font&gt;&lt;br /&gt;    &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Result &lt;font color="blue"&gt;varchar&lt;/font&gt;(50)&lt;br /&gt;&lt;br /&gt;    &lt;font color="blue"&gt;SET&lt;/font&gt; @Result = &lt;font color="magenta"&gt;CAST&lt;/font&gt;(&lt;font color="magenta"&gt;Day&lt;/font&gt;(@DateToConvert) &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(50)) + &lt;font color="red"&gt;'-'&lt;/font&gt; + &lt;br /&gt;                    &lt;font color="gray"&gt;Left&lt;/font&gt;(&lt;font color="magenta"&gt;DateName&lt;/font&gt;(m, @DateToConvert), 3) + &lt;font color="red"&gt;'-'&lt;/font&gt; + &lt;br /&gt;                    &lt;font color="magenta"&gt;CAST&lt;/font&gt;(&lt;font color="magenta"&gt;Year&lt;/font&gt;(@DateToConvert) &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(50))&lt;br /&gt;&lt;br /&gt;    &lt;font color="green"&gt;-- Return the result of the function&lt;/font&gt;&lt;br /&gt;    &lt;font color="blue"&gt;RETURN&lt;/font&gt; @Result;&lt;br /&gt;&lt;font color="blue"&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;div style="text-align:right;"&gt;&lt;a href="#sqldatetimetop"&gt;Back to Top&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;a id="dategetdaysinmonth"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;font color="green"&gt;-- =============================================&lt;br /&gt;-- Author:        unknown (I copied it from internet)&lt;br /&gt;-- Description:   Returns the Days in a Month&lt;br /&gt;--                parameters = Year and Month&lt;br /&gt;-- =============================================&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;CREATE FUNCTION&lt;/font&gt; [DateGetDaysInMonth] (@Year &lt;font color="blue"&gt;int&lt;/font&gt;, @Month &lt;font color="blue"&gt;int&lt;/font&gt;)&lt;br /&gt;&lt;font color="blue"&gt;RETURNS INT&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;    &lt;font color="blue"&gt;RETURN CASE WHEN&lt;/font&gt; @Month &lt;font color="gray"&gt;IN&lt;/font&gt; (1, 3, 5, 7, 8, 10, 12) &lt;font color="blue"&gt;THEN&lt;/font&gt; 31&lt;br /&gt;                &lt;font color="blue"&gt;WHEN&lt;/font&gt; @Month &lt;font color="gray"&gt;IN&lt;/font&gt; (4, 6, 9, 11) &lt;font color="blue"&gt;THEN&lt;/font&gt; 30&lt;br /&gt;                &lt;font color="blue"&gt;ELSE CASE WHEN&lt;/font&gt; (@Year % 4    = 0 &lt;font color="gray"&gt;AND&lt;/font&gt;&lt;br /&gt;                                @Year % 100 != 0) &lt;font color="blue"&gt;OR&lt;/font&gt;&lt;br /&gt;                               (@Year % 400  = 0)&lt;br /&gt;                          &lt;font color="blue"&gt;THEN&lt;/font&gt; 29&lt;br /&gt;                          &lt;font color="blue"&gt;ELSE&lt;/font&gt; 28&lt;br /&gt;                     &lt;font color="blue"&gt;END&lt;br /&gt;           END&lt;br /&gt;&lt;br /&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;div style="text-align:right;"&gt;&lt;a href="#sqldatetimetop"&gt;Back to Top&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;a id="dategettimeonly"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;font color="green"&gt;-- =============================================&lt;br /&gt;-- Author:  Arsalan Tamiz&lt;br /&gt;-- Description: Gets the Time from Date&lt;br /&gt;-- =============================================&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;CREATE FUNCTION&lt;/font&gt; [DateGetTimeOnly] &lt;br /&gt;(&lt;br /&gt; &lt;font color="green"&gt;-- Add the parameters for the function here&lt;/font&gt;&lt;br /&gt; @DateToFormat &lt;font color="blue"&gt;datetime&lt;/font&gt;&lt;br /&gt;)&lt;br /&gt;&lt;font color="blue"&gt;RETURNS varchar&lt;/font&gt;(100)&lt;br /&gt;&lt;font color="blue"&gt;AS&lt;br /&gt;BEGIN&lt;/font&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Declare the return variable here&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Result &lt;font color="blue"&gt;varchar&lt;/font&gt;(100);&lt;br /&gt; &lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @H &lt;font color="blue"&gt;varchar&lt;/font&gt;(3);&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Hour &lt;font color="blue"&gt;int&lt;/font&gt;;&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @M &lt;font color="blue"&gt;varchar&lt;/font&gt;(3); &lt;br /&gt;&lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @Hour = &lt;font color="magenta"&gt;DatePart&lt;/font&gt;(hh, @DateToFormat);&lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @M = &lt;font color="magenta"&gt;DateName&lt;/font&gt;(mi, @DateToFormat);&lt;br /&gt; &lt;font color="blue"&gt;If&lt;/font&gt; @M = &lt;font color="red"&gt;'0'&lt;/font&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @M = &lt;font color="red"&gt;'00'&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Add the T-SQL statements to compute the return value here&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @H = &lt;font color="magenta"&gt;CAST&lt;/font&gt;(&lt;font color="magenta"&gt;CASE&lt;/font&gt; &lt;font color="blue"&gt;WHEN&lt;/font&gt; @Hour &gt; 12 &lt;font color="blue"&gt;THEN&lt;/font&gt; @Hour - 12 &lt;font color="blue"&gt;ELSE CASE WHEN&lt;/font&gt; @Hour = 0 &lt;font color="blue"&gt;THEN&lt;/font&gt; 12 &lt;font color="blue"&gt;ELSE&lt;/font&gt; @Hour &lt;font color="blue"&gt;END END AS varchar&lt;/font&gt;);&lt;br /&gt; &lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @Result = @H + &lt;font color="red"&gt;':'&lt;/font&gt; + @M + &lt;font color="red"&gt;' '&lt;/font&gt; + &lt;font color="blue"&gt;CASE WHEN&lt;/font&gt; @Hour &gt;= 12 &lt;font color="blue"&gt;THEN&lt;/font&gt; &lt;font color="red"&gt;'PM'&lt;/font&gt; &lt;font color="blue"&gt;ELSE&lt;/font&gt; &lt;font color="red"&gt;'AM'&lt;/font&gt; &lt;font color="blue"&gt;END&lt;/font&gt;;&lt;br /&gt; &lt;br /&gt; &lt;font color="green"&gt;-- Return the result of the function&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;RETURN&lt;/font&gt; @Result;&lt;br /&gt;&lt;font color="blue"&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;div style="text-align:right;"&gt;&lt;a href="#sqldatetimetop"&gt;Back to Top&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;a id="dategetdateonly"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;font color="green"&gt;-- =============================================&lt;br /&gt;-- Author:  Arsalan Tamiz&lt;br /&gt;-- Description: Returns Date only from given Date&lt;br /&gt;--    That is removes the Time Part&lt;br /&gt;--    so that we can compare two dates&lt;br /&gt;-- =============================================&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;CREATE FUNCTION&lt;/font&gt; [DateGetDateOnly] &lt;br /&gt;(&lt;br /&gt; &lt;font color="green"&gt;-- Add the parameters for the function here&lt;/font&gt;&lt;br /&gt; @DateToConvert &lt;font color="blue"&gt;datetime&lt;/font&gt;&lt;br /&gt;)&lt;br /&gt;&lt;font color="blue"&gt;RETURNS datetime&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;/font&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Declare the return variable here&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Result &lt;font color="blue"&gt;datetime&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Add the T-SQL statements to compute the return value here&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @Result = &lt;font color="magenta"&gt;CAST&lt;/font&gt;(&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;(&lt;font color="blue"&gt;varchar&lt;/font&gt;(100), @DateToConvert, 112) &lt;font color="blue"&gt;AS datetime&lt;/font&gt;);&lt;br /&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Return the result of the function&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;RETURN&lt;/font&gt; @Result;&lt;br /&gt;&lt;font color="blue"&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;div style="text-align:right;"&gt;&lt;a href="#sqldatetimetop"&gt;Back to Top&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;a id="dategetmonthfirstdate"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;font color="green"&gt;-- =============================================&lt;br /&gt;-- Author:  Arsalan Tamiz&lt;br /&gt;-- Description: Gets the first date of month&lt;br /&gt;-- =============================================&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;CREATE FUNCTION&lt;/font&gt; [DateGetMonthFirstDate] &lt;br /&gt;(&lt;br /&gt; &lt;font color="green"&gt;-- Add the parameters for the function here&lt;/font&gt;&lt;br /&gt; @Month &lt;font color="blue"&gt;int&lt;/font&gt;&lt;br /&gt;)&lt;br /&gt;&lt;font color="blue"&gt;RETURNS datetime&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;/font&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Declare the return variable here&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Result &lt;font color="blue"&gt;datetime&lt;/font&gt;;&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Year &lt;font color="blue"&gt;int&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @Year = &lt;font color="magenta"&gt;Year&lt;/font&gt;(&lt;font color="magenta"&gt;GetDate&lt;/font&gt;());&lt;br /&gt;&lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @Result = &lt;font color="magenta"&gt;CAST&lt;/font&gt; (&lt;br /&gt;    &lt;font color="magenta"&gt;CAST&lt;/font&gt;(@Year &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(10)) + &lt;font color="red"&gt;'-'&lt;/font&gt; + &lt;br /&gt;    &lt;font color="magenta"&gt;CAST&lt;/font&gt;(@Month &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(2)) + &lt;font color="red"&gt;'-1'&lt;/font&gt; &lt;font color="blue"&gt;AS datetime&lt;/font&gt;&lt;br /&gt;    );&lt;br /&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Return the result of the function&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;RETURN&lt;/font&gt; @Result;&lt;br /&gt;&lt;font color="blue"&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;div style="text-align:right;"&gt;&lt;a href="#sqldatetimetop"&gt;Back to Top&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;a id="dategetmonthlastdate"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;font color="green"&gt;-- =============================================&lt;br /&gt;-- Author:  Arsalan Tamiz&lt;br /&gt;-- Description: Returns last date of month&lt;br /&gt;-- ***********************************************&lt;br /&gt;-- IMPORTANT: This function depends on [dbo].[DateGetDaysInMonth]() function&lt;br /&gt;--    which can be found above&lt;br /&gt;-- ***********************************************&lt;br /&gt;-- =============================================&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;CREATE FUNCTION&lt;/font&gt; [DateGetMonthLastDate] &lt;br /&gt;(&lt;br /&gt; &lt;font color="green"&gt;-- Add the parameters for the function here&lt;/font&gt;&lt;br /&gt; @Month &lt;font color="blue"&gt;int&lt;/font&gt;&lt;br /&gt;)&lt;br /&gt;&lt;font color="blue"&gt;RETURNS datetime&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;/font&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Declare the return variable here&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Result &lt;font color="blue"&gt;datetime&lt;/font&gt;;&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Year &lt;font color="blue"&gt;int&lt;/font&gt;;&lt;br /&gt; &lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @Year = &lt;font color="magenta"&gt;Year&lt;/font&gt;(&lt;font color="magenta"&gt;GetDate&lt;/font&gt;());&lt;br /&gt; &lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @Result = &lt;font color="magenta"&gt;CAST&lt;/font&gt; (&lt;br /&gt;    &lt;font color="magenta"&gt;CAST&lt;/font&gt;(@Year &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(10)) + &lt;font color="red"&gt;'-'&lt;/font&gt; + &lt;br /&gt;    &lt;font color="magenta"&gt;CAST&lt;/font&gt;(@Month &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(2)) + &lt;font color="red"&gt;'-'&lt;/font&gt; +&lt;br /&gt;    &lt;font color="magenta"&gt;CAST&lt;/font&gt;([dbo].[DateGetDaysInMonth](@Year, @Month) &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(2)) +&lt;br /&gt;    &lt;font color="blue"&gt;AS datetime&lt;/font&gt;&lt;br /&gt;    );&lt;br /&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Return the result of the function&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;RETURN&lt;/font&gt; @Result;&lt;br /&gt;&lt;font color="blue"&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;div style="text-align:right;"&gt;&lt;a href="#sqldatetimetop"&gt;Back to Top&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;a id="dategetmonthname"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;font color="green"&gt;-- =============================================&lt;br /&gt;-- Author:  Arsalan Tamiz&lt;br /&gt;-- Description: This function Retuns the name of month&lt;br /&gt;-- =============================================&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;CREATE FUNCTION&lt;/font&gt; [DateGetMonthName] &lt;br /&gt;(&lt;br /&gt; &lt;font color="green"&gt;-- Add the parameters for the function here&lt;/font&gt;&lt;br /&gt; @Month &lt;font color="blue"&gt;int&lt;/font&gt;&lt;br /&gt;)&lt;br /&gt;&lt;font color="blue"&gt;RETURNS varchar&lt;/font&gt;(100)&lt;br /&gt;&lt;font color="blue"&gt;AS&lt;br /&gt;BEGIN&lt;/font&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Declare the return variable here&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @Result &lt;font color="blue"&gt;varchar&lt;/font&gt;(100)&lt;br /&gt; &lt;font color="blue"&gt;DECLARE&lt;/font&gt; @d &lt;font color="blue"&gt;datetime&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @d = &lt;font color="magenta"&gt;CAST&lt;/font&gt;(&lt;font color="red"&gt;'2009-'&lt;/font&gt; + &lt;font color="magenta"&gt;CAST&lt;/font&gt;(@Month &lt;font color="blue"&gt;AS varchar&lt;/font&gt;(2)) + &lt;font color="red"&gt;'-1'&lt;/font&gt; &lt;font color="blue"&gt;AS datetime&lt;/font&gt;);&lt;br /&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Add the T-SQL statements to compute the return value here&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;SET&lt;/font&gt; @Result = &lt;font color="magenta"&gt;DateName&lt;/font&gt;(mm, @d);&lt;br /&gt;&lt;br /&gt; &lt;font color="green"&gt;-- Return the result of the function&lt;/font&gt;&lt;br /&gt; &lt;font color="blue"&gt;RETURN&lt;/font&gt; @Result;&lt;br /&gt;&lt;font color="blue"&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;div style="text-align:right;"&gt;&lt;a href="#sqldatetimetop"&gt;Back to Top&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-3948590518106362624?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_ozUOZgYUBEK8138vC2y3ozy9Zo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_ozUOZgYUBEK8138vC2y3ozy9Zo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_ozUOZgYUBEK8138vC2y3ozy9Zo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_ozUOZgYUBEK8138vC2y3ozy9Zo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/CeWBo9HBYTI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/3948590518106362624/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=3948590518106362624" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/3948590518106362624" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/3948590518106362624" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/CeWBo9HBYTI/sql-server-date-time-useful-functions.html" title="SQL Server Date Time Useful Functions" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2009/03/sql-server-date-time-useful-functions.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-6303981005839181608</id><published>2009-02-14T11:01:00.004+05:00</published><updated>2009-02-14T11:14:36.624+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="VB.net" /><category scheme="http://www.blogger.com/atom/ns#" term="Custom Controls" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">Notification Bar Control For Windows Forms (Win Forms)</title><content type="html">&lt;a href="http://1.bp.blogspot.com/_HfnUI4smnYA/SZZeXp9Wa8I/AAAAAAAAAH8/Hj9uj_vU2mk/s1600-h/NotificationBar.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 129px;" src="http://1.bp.blogspot.com/_HfnUI4smnYA/SZZeXp9Wa8I/AAAAAAAAAH8/Hj9uj_vU2mk/s320/NotificationBar.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5302529371768515522" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is simple Notification Bar control (like we see in Internet Explorer). Gives application a good look. Note that I haven't done much thing, you can customize is further if you like. It supports blinking too.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;ShowNotification()&lt;/strong&gt; method to display the Notification.&lt;br /&gt;&lt;strong&gt;BlinkTimes&lt;/strong&gt; property to set the Number of Times to blink.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Download Source Code:&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://cid-c23746227866488d.skydrive.live.com/self.aspx/Public/NotificationBar.zip"&gt;Notificationbar.zip&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-6303981005839181608?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/wHRDZzQ7qvR3xUKa5Y0qyJFoKLU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wHRDZzQ7qvR3xUKa5Y0qyJFoKLU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/wHRDZzQ7qvR3xUKa5Y0qyJFoKLU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wHRDZzQ7qvR3xUKa5Y0qyJFoKLU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/2bRwa9Wyxdg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/6303981005839181608/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=6303981005839181608" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/6303981005839181608" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/6303981005839181608" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/2bRwa9Wyxdg/notification-bar-control-for-windows.html" title="Notification Bar Control For Windows Forms (Win Forms)" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_HfnUI4smnYA/SZZeXp9Wa8I/AAAAAAAAAH8/Hj9uj_vU2mk/s72-c/NotificationBar.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2009/02/notification-bar-control-for-windows.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-7763839873142305988</id><published>2009-01-26T12:44:00.003+05:00</published><updated>2009-01-26T13:45:08.358+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="VB.net" /><category scheme="http://www.blogger.com/atom/ns#" term="Win Forms" /><category scheme="http://www.blogger.com/atom/ns#" term="Custom Controls" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="DataGridView" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">DataGridView Custom Cell ToolTip</title><content type="html">&lt;a href="http://4.bp.blogspot.com/_HfnUI4smnYA/SX1qdXLPhLI/AAAAAAAAAH0/joQsoUD2JmA/s1600-h/DGVCustomCellToolTip.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 217px;" src="http://4.bp.blogspot.com/_HfnUI4smnYA/SX1qdXLPhLI/AAAAAAAAAH0/joQsoUD2JmA/s320/DGVCustomCellToolTip.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5295505789527491762" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Level:&lt;/strong&gt; Intermediate&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;DataGridView Control&lt;/li&gt;&lt;li&gt;Windows Forms&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;We have a built-in ToolTip for each Cell in DataGridView control. Which is displayed when the text is long and cannot be displayed completely in Cell. But my requirement was to create a custom ToolTip (as displayed in above image).&lt;br /&gt;&lt;br /&gt;There were 2 main requirements,&lt;br /&gt;&lt;br /&gt;1) ToolTip should be displayed permanently that is, it should NOT be disappeared automatically after sometime.&lt;br /&gt;2) I want to have a fancy look of my ToolTip (again see the image).&lt;br /&gt;&lt;br /&gt;For this purpose we can also use the .net's built-in ToolTip control. Which can have a little fancy look by setting some of its properties like &lt;strong&gt;IsBubble&lt;/strong&gt;, &lt;strong&gt;ToolTipIcon&lt;/strong&gt; and &lt;strong&gt;ToolTipTitle&lt;/strong&gt;. Also the ToolTip control can be more customized by using &lt;strong&gt;OwnerDraw&lt;/strong&gt; mode. But still I would like to use my own ToolTip window. Because to me, this is more easier to do.&lt;br /&gt;&lt;br /&gt;Simply I implemented it by creating a new window for ToolTip and I show this window when mouse enters in a cell. But to make it more user friendly, I have used a Timer control. So that whenever mouse enters in a Cell I start timer and in Timer's Tick Event Handler, I display the ToolTip window.&lt;br /&gt;&lt;br /&gt;Few things to be considered here,&lt;br /&gt;&lt;br /&gt;1) DataGridView's &lt;strong&gt;ShowCellToolTips&lt;/strong&gt; property should be set to &lt;strong&gt;False&lt;/strong&gt;&lt;br /&gt;2) Decide where to display the ToolTip window&lt;br /&gt;&lt;br /&gt;So in my case I decided to display the ToolTip window just on the Cell. OK this is NOT just straight. We first need to get the Cell's actual Coordinate in DataGridView by executing DataGridView's &lt;strong&gt;GetCellDisplayRectangle()&lt;/strong&gt; function. Then we need to convert these coordinates into Screen's Coordinates by calling the DataGridView's &lt;strong&gt;PointToScreen()&lt;/strong&gt; function.&lt;br /&gt;&lt;br /&gt;Please note that, to display our own custom ToolTip window on our given position we need to set its property &lt;strong&gt;StartPosition = Manual&lt;/strong&gt;, which I have discussed in my earlier post &lt;a href="http://arsalantamiz.blogspot.com/2008/11/setting-window-form-position.html"&gt;Setting Window / Form Position Programmatically&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Another thing I have added in the ToolTip window is the &lt;strong&gt;Close Button&lt;/strong&gt;. Which is actually a &lt;strong&gt;NON Focusable&lt;/strong&gt; button as I have discussed my previous post &lt;a href="http://arsalantamiz.blogspot.com/2009/01/not-focusable-not-selectable-button.html"&gt;NOT Focusable / NOT Selectable Button&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Download Source:&lt;br /&gt;&lt;a href="http://cid-c23746227866488d.skydrive.live.com/self.aspx/arsalantamizblogspotfiles/DataGridViewCustomCellToolTip.zip"&gt;DataGridViewCustomCellToolTip.zip&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-7763839873142305988?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/AnXas6v6gp0YHukBlEFZHJxWibc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AnXas6v6gp0YHukBlEFZHJxWibc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/AnXas6v6gp0YHukBlEFZHJxWibc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AnXas6v6gp0YHukBlEFZHJxWibc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/jZDJCXKtsR0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/7763839873142305988/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=7763839873142305988" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/7763839873142305988" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/7763839873142305988" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/jZDJCXKtsR0/datagridview-custom-cell-tooltip.html" title="DataGridView Custom Cell ToolTip" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_HfnUI4smnYA/SX1qdXLPhLI/AAAAAAAAAH0/joQsoUD2JmA/s72-c/DGVCustomCellToolTip.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2009/01/datagridview-custom-cell-tooltip.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-673291084176235702</id><published>2009-01-23T15:10:00.006+05:00</published><updated>2009-01-23T15:25:28.959+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="VB.net" /><category scheme="http://www.blogger.com/atom/ns#" term="Custom Controls" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">NOT Focusable / NOT Selectable Button</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Intermediate&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;User Controls&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;Few days back I was creating a user control like ComboBox. In ComboBox we have a Drop Down button at the right side, which cannot have focus. This button can only be clicked by mouse to open the Drop Down portion (Alt+Down is the shortcut).&lt;br /&gt;&lt;br /&gt;Similarly my control also have a button on right. I decided to make that button just like the Drop Down button of ComboBox. For this purpose I added a plain Class in my project and then put the following Code,&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;font color="blue"&gt;Public Class&lt;/font&gt; NotSelectableButton&lt;br /&gt;    &lt;font color="blue"&gt;Inherits&lt;/font&gt; Button&lt;br /&gt;&lt;br /&gt;    &lt;font color="blue"&gt;Public Sub New&lt;/font&gt;()&lt;br /&gt;        &lt;font color="blue"&gt;MyBase&lt;/font&gt;.&lt;font color="blue"&gt;New&lt;/font&gt;()&lt;br /&gt;        &lt;font color="green"&gt;' following line will make this button Not Focusable&lt;/font&gt;&lt;br /&gt;        SetStyle(ControlStyles.Selectable, &lt;font color="blue"&gt;False&lt;/font&gt;)&lt;br /&gt;    &lt;font color="blue"&gt;End Sub&lt;/font&gt;&lt;br /&gt;&lt;font color="blue"&gt;End Class&lt;/font&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-673291084176235702?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mEWITTlxFWjwUSGKRlhATmqos9o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mEWITTlxFWjwUSGKRlhATmqos9o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mEWITTlxFWjwUSGKRlhATmqos9o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mEWITTlxFWjwUSGKRlhATmqos9o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/1zvNO4NJxV0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/673291084176235702/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=673291084176235702" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/673291084176235702" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/673291084176235702" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/1zvNO4NJxV0/not-focusable-not-selectable-button.html" title="NOT Focusable / NOT Selectable Button" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2009/01/not-focusable-not-selectable-button.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-2938315967681550261</id><published>2009-01-17T12:28:00.005+05:00</published><updated>2009-01-17T12:46:42.723+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Functions" /><category scheme="http://www.blogger.com/atom/ns#" term="VB.net" /><category scheme="http://www.blogger.com/atom/ns#" term="FTP" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">FTP File Upload Error</title><content type="html">It seems that our Network Administrator has changed some settings because my previous file uploading code is NOT working. And giving the following exception:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The server returned an address in response to the PASV command that is different than the address to which the FTP connection was made.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I was using the VB.net &lt;strong&gt;My&lt;/strong&gt; namespace,&lt;pre class="code"&gt;&lt;font color="blue"&gt;My&lt;/font&gt;.Computer.Network.UploadFile(&lt;font color="red"&gt;"C:\SomeFile.txt"&lt;/font&gt;, &lt;font color="red"&gt;"ftp://ftpsite/somefile.txt"&lt;/font&gt;, &lt;font color="red"&gt;"userid"&lt;/font&gt;, &lt;font color="red"&gt;"pwd"&lt;/font&gt;)&lt;/pre&gt;So I Googled about that error and found some dicussion on &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/661a537b-813f-465c-bdd3-e1df975b7e3c"&gt;MSDN forums&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Then I modified and created my own upload function as,&lt;pre class="code"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; UploadFile(&lt;font color=blue&gt;ByVal&lt;/font&gt; sDestination &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;String&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; sSource &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;String&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; sUserID &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;String&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; sPassword &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;String&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; i &lt;font color=blue&gt;As&lt;/font&gt; System.Net.FtpWebRequest&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; us &lt;font color=blue&gt;As&lt;/font&gt; System.IO.Stream&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; filebytes &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Byte&lt;/font&gt;()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' create the FTP Web Request&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i = System.Net.WebRequest.Create(sDestination)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' set credentials&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i.Credentials = &lt;font color=blue&gt;New&lt;/font&gt; System.Net.NetworkCredential(sUserID, sPassword)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' method = Upload File&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i.Method = System.Net.WebRequestMethods.Ftp.UploadFile&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i.UsePassive = &lt;font color=blue&gt;False&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i.Proxy = &lt;font color=blue&gt;Nothing&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' get the Request Stream&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;us = i.GetRequestStream()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' get the file bytes from source&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filebytes = My.Computer.FileSystem.ReadAllBytes(sSource)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' write the bytes in stream&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;us.Write(filebytes, 0, filebytes.Length)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' close the stream&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;us.Close()&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;/pre&gt;&lt;div style="background-color:yellow;border-style:solid;border-width:2px;border-color:red;padding:10px;"&gt;Warning! Above function will read &lt;strong&gt;all the bytes (in one go)&lt;/strong&gt; from file. Which is NOT a good practice for &lt;strong&gt;larger files&lt;/strong&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-2938315967681550261?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6ay_ZYE5ZiB2xKB5iv9wPQMOieE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6ay_ZYE5ZiB2xKB5iv9wPQMOieE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6ay_ZYE5ZiB2xKB5iv9wPQMOieE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6ay_ZYE5ZiB2xKB5iv9wPQMOieE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/FKVU0aVSsio" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/2938315967681550261/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=2938315967681550261" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/2938315967681550261" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/2938315967681550261" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/FKVU0aVSsio/ftp-file-upload-error.html" title="FTP File Upload Error" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2009/01/ftp-file-upload-error.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-943483184740389024</id><published>2009-01-02T11:14:00.006+05:00</published><updated>2009-01-02T11:57:44.483+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Javascript" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML Tips/Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.net" /><category scheme="http://www.blogger.com/atom/ns#" term="AJAX" /><title type="text">Another way of accessing a file on Web Server (Javascript/ASP.net)</title><content type="html">Few days back while working on back-end of a Web Portal. I was trying to create an &lt;strong&gt;Anchor Tag (&amp;lt;a&amp;gt;)&lt;/strong&gt; in such a way that a log should also be created whenever that anchor tag is clicked by user.&lt;br /&gt;&lt;br /&gt;So there are couple of techniques.&lt;br /&gt;&lt;br /&gt;Approach #1:&lt;br /&gt;On Click: Post back to server create the log and redirect to the URL.&lt;br /&gt;&lt;br /&gt;Approach #2:&lt;br /&gt;Use AJAX&lt;br /&gt;&lt;br /&gt;So I used the 2nd approach. For this purpose I first created a Javascript function as,&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;First Try:&lt;/strong&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;font color="blue"&gt;function&lt;/font&gt; createlog(param1, param2) {&lt;br /&gt; &lt;font color="blue"&gt;var&lt;/font&gt; xmlHttp;&lt;br /&gt; &lt;font color="blue"&gt;try&lt;/font&gt;&lt;br /&gt;  {  &lt;font color="green"&gt;// Firefox, Opera 8.0+, Safari&lt;/font&gt;&lt;br /&gt;  xmlHttp=&lt;font color="blue"&gt;new&lt;/font&gt; XMLHttpRequest();  &lt;br /&gt; }&lt;br /&gt; &lt;font color="blue"&gt;catch&lt;/font&gt; (e)&lt;br /&gt; {  &lt;font color="green"&gt;// Internet Explorer&lt;/font&gt;&lt;br /&gt;  &lt;font color="blue"&gt;try&lt;/font&gt;&lt;br /&gt;  {&lt;br /&gt;   xmlHttp=&lt;font color="blue"&gt;new&lt;/font&gt; ActiveXObject(&lt;font color="red"&gt;"Msxml2.XMLHTTP"&lt;/font&gt;);    &lt;br /&gt;  }&lt;br /&gt;  &lt;font color="blue"&gt;catch&lt;/font&gt; (e)&lt;br /&gt;      {&lt;br /&gt;   &lt;font color="blue"&gt;try&lt;/font&gt;&lt;br /&gt;   {&lt;br /&gt;    xmlHttp=&lt;font color="blue"&gt;new&lt;/font&gt; ActiveXObject(&lt;font color="red"&gt;"Microsoft.XMLHTTP"&lt;/font&gt;);&lt;br /&gt;   }&lt;br /&gt;       &lt;font color="blue"&gt;catch&lt;/font&gt; (e)&lt;br /&gt;   {&lt;br /&gt;    alert(&lt;font color="red"&gt;"Your browser does not support AJAX!"&lt;/font&gt;);&lt;br /&gt;    &lt;font color="blue"&gt;return false&lt;/font&gt;;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;font color="blue"&gt;try&lt;/font&gt;&lt;br /&gt; {&lt;br /&gt;  &lt;font color="blue"&gt;var&lt;/font&gt; u;&lt;br /&gt;  u = &lt;font color="red"&gt;"createlog.aspx?param1="&lt;/font&gt; + param1 + &lt;font color="red"&gt;"&amp;amp;param2="&lt;/font&gt; + param2;&lt;br /&gt;  xmlHttp.open(&lt;font color="red"&gt;"POST"&lt;/font&gt;, u, &lt;font color="blue"&gt;false&lt;/font&gt;);&lt;br /&gt;  xmlHttp.send(&lt;font color="blue"&gt;null&lt;/font&gt;);&lt;br /&gt;  &lt;font color="blue"&gt;return true&lt;/font&gt;;&lt;br /&gt; }&lt;br /&gt; &lt;font color="blue"&gt;catch&lt;/font&gt; (e)&lt;br /&gt; {&lt;br /&gt;  &lt;font color="blue"&gt;return false&lt;/font&gt;;&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So this is an example function. Which will create a log by executing a "createlog.aspx" file on server which accepts 2 parameters in QueryString. The above function is simply using the &lt;strong&gt;XMLHttpRequest()&lt;/strong&gt; object for AJAX call.&lt;br /&gt;&lt;br /&gt;Then we can use this function in an anchor tag as,&lt;br /&gt;&lt;pre class="code"&gt;&amp;lt;a href="http://www.domain.com" onclick="return createlog(1, 2);"&amp;gt;www.domain.com&amp;lt;/a&amp;gt;&lt;/pre&gt;&lt;br /&gt;When user will click on the link the &lt;strong&gt;createlog()&lt;/strong&gt; function will be executed first. Which then will create the log on server and then redirect to the link.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Second Try:&lt;/strong&gt;&lt;br /&gt;Secondly I looked in the Google's Result Page. Because they are doing this also. Whenever we click on a result, Google redirects to that URL directly (without posting back) but also keeps the track of clicking. I looked into their Javascript and found a very interesting thing. And hence modified my Javascript function to this,&lt;br /&gt;&lt;pre class="code"&gt;&lt;font color="blue"&gt;function&lt;/font&gt; createlog(param1, param2) {&lt;br /&gt; &lt;font color="blue"&gt;var&lt;/font&gt; u = &lt;font color="red"&gt;"createlog.aspx?param1="&lt;/font&gt; + param1 + &lt;font color="red"&gt;"&amp;amp;param2="&lt;/font&gt; + param2;&lt;br /&gt; (&lt;font color="blue"&gt;new&lt;/font&gt; Image).src = u;&lt;br /&gt; &lt;font color="blue"&gt;return true&lt;/font&gt;;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Because my requirement is to just execute the "createlog.aspx" file on the server. I do NOT need the returned value. That is why XMLHttpRequest() is NOT critically required in this scenario. On the other hand &lt;strong&gt;(new Image).src&lt;/strong&gt; approach is lot simpler.&lt;br /&gt;&lt;br /&gt;&lt;div style="padding:10px 10px 10px 10px; background-color:lightyellow; border-style:solid; border-width:1px; border-color:orange"&gt;What happens is that the browser creates an Image object and go to the "source" (in this case my createlog.aspx) which actually do NOT return any data (i.e. image bytes). But by going to that URL it actually is executed on server. And the Image object is then discarded at the end of function (I guess).&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;One more thing I found was Google is using "onmousedown" event instead of "onclick". I don't know exactly the benefits but I have experience that "onclick" event is NOT fired (on some browsers) when we right click and open the link in new window or tab. "onmousedown" event is triggered each time we click on link even if we right click on it. So it seems that this is NOT a good approach to use "onmousedown". But I have checked that whenever we right/left click on the link for the first time, the file "createlog.aspx" is executed on server. But it does NOT execute, if we click again. I think this is due to cache maybe.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-943483184740389024?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rRQqdELzqWoKnBARHURA79_WGpI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rRQqdELzqWoKnBARHURA79_WGpI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rRQqdELzqWoKnBARHURA79_WGpI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rRQqdELzqWoKnBARHURA79_WGpI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/13wSPg60NXA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/943483184740389024/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=943483184740389024" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/943483184740389024" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/943483184740389024" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/13wSPg60NXA/another-way-of-accessing-file-on-web.html" title="Another way of accessing a file on Web Server (Javascript/ASP.net)" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2009/01/another-way-of-accessing-file-on-web.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-5939653265951594517</id><published>2008-12-23T12:14:00.004+05:00</published><updated>2008-12-23T12:28:17.840+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Functions" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">Image to Byte Array and Byte Array to Image</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Intermediate&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;Image Class&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;Here are simple functions that convert an Image into Byte Array and Byte Array into Image. An image is required to be converted into bytes array when we save it in Database, hence on reading the bytes from database, it needs to be converted back into image.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Function&lt;/font&gt; BytesToImage(&lt;font color=blue&gt;ByVal&lt;/font&gt; ImageBytes() &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Byte&lt;/font&gt;) &lt;font color=blue&gt;As&lt;/font&gt; Image&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; imgNew &lt;font color=blue&gt;As&lt;/font&gt; Image&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; memImage &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;New&lt;/font&gt; System.IO.MemoryStream(ImageBytes)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;imgNew = Image.FromStream(memImage)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return imgNew&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Function&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Function&lt;/font&gt; ImageToBytes(&lt;font color=blue&gt;ByVal&lt;/font&gt; Image &lt;font color=blue&gt;As&lt;/font&gt; Image) &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Byte&lt;/font&gt;()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; memImage &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;New&lt;/font&gt; System.IO.MemoryStream&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; bytImage() &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Byte&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Image.Save(memImage, Image.RawFormat)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bytImage = memImage.GetBuffer()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return bytImage&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Function&lt;/font&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-5939653265951594517?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2dNylz-oZTJhdMQz_TWAb59Q2BM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2dNylz-oZTJhdMQz_TWAb59Q2BM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2dNylz-oZTJhdMQz_TWAb59Q2BM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2dNylz-oZTJhdMQz_TWAb59Q2BM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/sj_GLWq4K-Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/5939653265951594517/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=5939653265951594517" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5939653265951594517" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5939653265951594517" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/sj_GLWq4K-Q/image-to-byte-array-and-byte-array-to.html" title="Image to Byte Array and Byte Array to Image" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/12/image-to-byte-array-and-byte-array-to.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-5950252544519798374</id><published>2008-12-18T22:44:00.003+05:00</published><updated>2009-01-02T10:47:02.565+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Javascript" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML Tips/Tricks" /><title type="text">Java Script Function to Show Flash Banner</title><content type="html">Usually I develop Desktop Application. But sometimes I also get involve in Web Development. So we were developing a Website in which we were trying to create a Flash Banner rotator. To accomplish this there are several techniques, but I created the following Java Script function for our Web Developer.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;font color="blue"&gt;function&lt;/font&gt; showflashbanner(htmlobjectid, flashfilename, width, height) {&lt;br /&gt;    &lt;font color="blue"&gt;var&lt;/font&gt; script;&lt;br /&gt;    script = &lt;font color="red"&gt;"&amp;lt;object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' "&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"width='"&lt;/font&gt; + width + &lt;font color="red"&gt;"' height='"&lt;/font&gt; + height + &lt;font color="red"&gt;"' \&amp;gt;"&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"&amp;lt;param name='movie' "&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"value='"&lt;/font&gt; + flashfilename + &lt;font color="red"&gt;"' /\&amp;gt;"&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"&amp;lt;param name='quality' value='high' /\&amp;gt;"&lt;/font&gt; + &lt;br /&gt;             &lt;font color="red"&gt;"&amp;lt;embed src='"&lt;/font&gt; + flashfilename + &lt;font color="red"&gt;"' "&lt;/font&gt; + &lt;br /&gt;             &lt;font color="red"&gt;"quality='high' "&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' "&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"type='application/x-shockwave-flash'"&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"width='"&lt;/font&gt; + width + &lt;font color="red"&gt;"'"&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"height='"&lt;/font&gt; + height + &lt;font color="red"&gt;"'\&amp;gt'"&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"&amp;lt;/embed\&amp;gt;"&lt;/font&gt; +&lt;br /&gt;             &lt;font color="red"&gt;"&amp;lt;/object\&amp;gt;"&lt;/font&gt;;&lt;br /&gt;    &lt;font color="blue"&gt;document&lt;/font&gt;.getElementById(htmlobjectid).innerHTML = script;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br /&gt;&lt;pre class="code"&gt;&amp;lt;body onload="showflashbanner('bannercontainer', 'http://www.mywebsite.com/banners/banner1.swf', 720, 100)"&amp;gt;&lt;br /&gt;&amp;lt;div id="bannercontainer"&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;/pre&gt;&lt;br /&gt;As you can see the above example we have used "div" as a Banner container. Then we are passing this div's id in our function so the Flash File will be loaded in it.&lt;br /&gt;&lt;br /&gt;The Web developer then used this function by creating an Array of Flash Files. He also created another function in which he used &lt;strong&gt;setTimeout&lt;/strong&gt; function. So the function calls itself after some time with new Flash File.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-5950252544519798374?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-inD5JndHBgaSCyhMEVjLmR7JGw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-inD5JndHBgaSCyhMEVjLmR7JGw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-inD5JndHBgaSCyhMEVjLmR7JGw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-inD5JndHBgaSCyhMEVjLmR7JGw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/AkSfbMtFRI8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/5950252544519798374/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=5950252544519798374" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5950252544519798374" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5950252544519798374" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/AkSfbMtFRI8/java-script-function-to-show-flash.html" title="Java Script Function to Show Flash Banner" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/12/java-script-function-to-show-flash.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-4559020116112540515</id><published>2008-11-18T14:21:00.003+05:00</published><updated>2008-11-18T14:53:13.149+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Win Forms" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">Setting Window / Form Position Programmatically</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Beginner&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;Windows Forms&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;While working with Windows Forms we sometimes require to set the Window/Form Position manually before we show it. Consider the following code:&lt;br /&gt;&lt;pre class="code"&gt;&lt;font color=blue&gt;Dim&lt;/font&gt; frmNew &lt;font color=blue&gt;as&lt;/font&gt; Form2&lt;br /&gt;frmNew = &lt;font color=blue&gt;New&lt;/font&gt; Form2()&lt;br /&gt;frmNew.Location = &lt;font color=blue&gt;New&lt;/font&gt; Point(10, 10)&lt;br /&gt;frmNew.Show()&lt;/pre&gt;&lt;br /&gt;If we execute the above code, it is NOT sure that window will be displayed at 10, 10. Because we haven't set the &lt;strong&gt;StartPosition&lt;/strong&gt; property. By default this property is equal to &lt;strong&gt;WindowsDefaultLocation&lt;/strong&gt; that is why whenever we display the Form, Windows Operating system choose where to put it. And if we change &lt;strong&gt;Location&lt;/strong&gt; after the &lt;strong&gt;frmNew.Show()&lt;/strong&gt;, then our location will set.&lt;br /&gt;&lt;br /&gt;To set the &lt;strong&gt;Location&lt;/strong&gt; programmatically we should first set the &lt;strong&gt;StartPosition&lt;/strong&gt; property as,&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;font color=blue&gt;Dim&lt;/font&gt; frmNew &lt;font color=blue&gt;as&lt;/font&gt; Form2&lt;br /&gt;frmNew = &lt;font color=blue&gt;New&lt;/font&gt; Form2()&lt;br /&gt;frmNew.StartPosition = FormStartPosition.Manual&lt;br /&gt;frmNew.Location = &lt;font color=blue&gt;New&lt;/font&gt; Point(10, 10)&lt;br /&gt;frmNew.Show()&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-4559020116112540515?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/O-__-UfsKfTZETH2w7vHaivO0Ak/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O-__-UfsKfTZETH2w7vHaivO0Ak/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/O-__-UfsKfTZETH2w7vHaivO0Ak/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O-__-UfsKfTZETH2w7vHaivO0Ak/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/meVIUdW4i0Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/4559020116112540515/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=4559020116112540515" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/4559020116112540515" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/4559020116112540515" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/meVIUdW4i0Q/setting-window-form-position.html" title="Setting Window / Form Position Programmatically" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/11/setting-window-form-position.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-5354704768478083606</id><published>2008-10-16T11:52:00.002+06:00</published><updated>2008-10-16T12:42:39.662+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML Tips/Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="Web Development" /><title type="text">HTML Anchor Tag (&lt;a&gt; Link) with NO Redirection</title><content type="html">Although this Blog is purely for Visual Basic Windows Forms Application Development. But I think we can discuss other stuff too.&lt;br /&gt;&lt;br /&gt;So meanwhile working with HTML, I was trying to create an Anchor with a href defined but the link should NOT work. Click the following link,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.google.com" onclick="return false;"&gt;Google&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;As you can see the above link should redirect this page to Google, but it is NOT redirecting it. OK now try to open the link in a new Tab (if you are using a borwser which has tabbed browsing support, i.e. Ctrl+Click). This time it should work. Here is the HTML,&lt;br /&gt;&lt;pre class="code"&gt;&amp;lt;a href="http://www.google.com" onclick="return false;"&amp;gt;Google&amp;lt;/a&amp;gt;&lt;/pre&gt;&lt;br /&gt;As you can see in above "onclick" event we have executed a little javascript which returns false. This is the statement which is suppressing the default behaviour of anchor. Some sites handle it like this,&lt;br /&gt;&lt;br /&gt;&lt;a href="javascript:void(0);" onclick="alert('You Clicked the Link');"&gt;Google&lt;/a&gt;&lt;br /&gt;&lt;pre class="code"&gt;&amp;lt;a href="javascript:void(0);" onclick="alert('You Clicked the Link');"&amp;gt;Google&amp;lt;/a&amp;gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-5354704768478083606?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/u0FXUCjhVJ1B9k52FlBCy8ZmVOE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/u0FXUCjhVJ1B9k52FlBCy8ZmVOE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/u0FXUCjhVJ1B9k52FlBCy8ZmVOE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/u0FXUCjhVJ1B9k52FlBCy8ZmVOE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/_USHyAB3M9I" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/5354704768478083606/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=5354704768478083606" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5354704768478083606" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5354704768478083606" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/_USHyAB3M9I/html-anchor-tag-link-with-no.html" title="HTML Anchor Tag (&amp;lt;a&amp;gt; Link) with NO Redirection" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/10/html-anchor-tag-link-with-no.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-8784433998371889185</id><published>2008-09-14T13:27:00.006+06:00</published><updated>2008-10-07T12:08:13.886+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Beginner Topics" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="DataGridView" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Binding" /><title type="text">Binding DataGridView ComboBox Column</title><content type="html">&lt;a href="http://4.bp.blogspot.com/_HfnUI4smnYA/SMy9zcVAwyI/AAAAAAAAAF0/l4XCC6_EyXQ/s1600-h/OrderForm.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_HfnUI4smnYA/SMy9zcVAwyI/AAAAAAAAAF0/l4XCC6_EyXQ/s320/OrderForm.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5245776357455086370" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Level:&lt;/strong&gt; Beginner&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;Data Binding&lt;/li&gt;&lt;li&gt;DataGridView&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;We use DataGridView control lots of times while developing a Data Driven Application. We usually bind the DataGridView control with some BindingSource. Also we can bind the DataGridView's ComboBox Column to some other BindingSource. That is DataGridView has different DataSource and it's ComboBox column has a different. Consider the following scenario,&lt;br /&gt;&lt;br /&gt;We have following Typed DataSet,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_HfnUI4smnYA/SMy-0Uq2GcI/AAAAAAAAAF8/hyn6sTgyHJo/s1600-h/OrderDataSet.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_HfnUI4smnYA/SMy-0Uq2GcI/AAAAAAAAAF8/hyn6sTgyHJo/s320/OrderDataSet.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5245777472090675650" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div align="center"&gt;OrderDataSet&lt;/div&gt;&lt;br /&gt;First we will create a simple User Interface,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_HfnUI4smnYA/SM0fW_OawDI/AAAAAAAAAGU/Wf2mTOjuubM/s1600-h/OrderForm2.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_HfnUI4smnYA/SM0fW_OawDI/AAAAAAAAAGU/Wf2mTOjuubM/s320/OrderForm2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5245883620745986098" /&gt;&lt;/a&gt;&lt;br /&gt;As you can see in the above figure, the DataGridView control is bind with &lt;strong&gt;OrderDetail&lt;/strong&gt; Table. Note that the Product_ID column is displaying ID which is NOT a friendly approach. Instead Product Name should be displayed here. We can use the DataGridView's ComboBox Column here, in which we will populate all the products.&lt;br /&gt;&lt;br /&gt;The main point to be focused here is that, we will be binding the DataGridView control with the same OrderDetail DataTable, in which there is no Product_Name column. But on front-end the Product_ID column will be set to ComboBox Column in which we will populate the Products' Name.&lt;br /&gt;&lt;br /&gt;Since we need to populate the ComboBox with Products' Name. Therefore we will add another Typed DataSet and BindingSource to our Form,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_HfnUI4smnYA/SOrslBq8clI/AAAAAAAAAGc/ZrtWH3SzPJM/s1600-h/DGVCBProductDataSet.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_HfnUI4smnYA/SOrslBq8clI/AAAAAAAAAGc/ZrtWH3SzPJM/s320/DGVCBProductDataSet.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5254272036128977490" /&gt;&lt;/a&gt;&lt;br /&gt;We have bind our &lt;strong&gt;ProductBindingSource&lt;/strong&gt; with &lt;strong&gt;ProductDataSet&lt;/strong&gt; which contains &lt;strong&gt;Product&lt;/strong&gt; DataTable. We will fill this table in &lt;strong&gt;Form_Load&lt;/strong&gt; event Handler.&lt;br /&gt;&lt;br /&gt;&lt;div style="padding:10px 10px 10px 10px; background-color:lightyellow; border-style:solid; border-width:1px; border-color:orange"&gt;IMPORTANT: This table needs to be filled before we fill the OrderDataSet OR at-least before the OrderDetail DataGridView is displayed&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Now we need to setup the Product_ID column. First set the ColumnType of Product_ID column to DataGridViewComboBoxColumn and then set the properties as,&lt;ul&gt;&lt;li&gt;DataPropertyName = Product_ID&lt;/li&gt;&lt;li&gt;DataSource = ProductBindingSource&lt;/li&gt;&lt;li&gt;DisplayMember = Product_Name&lt;/li&gt;&lt;li&gt;ValueMember = Product_ID&lt;/li&gt;&lt;/ul&gt;&lt;a href="http://2.bp.blogspot.com/_HfnUI4smnYA/SOrv1LYltjI/AAAAAAAAAGk/iCy93lAN6Kg/s1600-h/DGVCBProperties.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_HfnUI4smnYA/SOrv1LYltjI/AAAAAAAAAGk/iCy93lAN6Kg/s320/DGVCBProperties.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5254275612149134898" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;DataPropertyName&lt;/strong&gt;: tells that Product_ID column of OrderDetail DataTable should be updated&lt;br /&gt;&lt;strong&gt;DataSource&lt;/strong&gt;: is the source from where the list of Products will be taken, in this case the ProductBindingSource which is actually bind with Product DataTable&lt;br /&gt;&lt;strong&gt;DisplayMember&lt;/strong&gt;: Column of Product DataTable which should be used to display in DataGridView control&lt;br /&gt;&lt;strong&gt;ValueMember&lt;/strong&gt;: Column of Product DataTable which should be used to set the Value in DataGridView which ultemately will send the value in OrderDetail DataTable&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_HfnUI4smnYA/SOr40qkxclI/AAAAAAAAAGs/GyvYtUWH7jo/s1600-h/DGVCBBindingExplain.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_HfnUI4smnYA/SOr40qkxclI/AAAAAAAAAGs/GyvYtUWH7jo/s320/DGVCBBindingExplain.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5254285498946515538" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Download:&lt;br /&gt;&lt;a href="http://cid-c23746227866488d.skydrive.live.com/self.aspx/Public/BindingDataGridViewComboBox.zip"&gt;BindingDataGridViewComboBox.zip&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-8784433998371889185?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rxkrDXLcZ3W2wzUrpwm5zSK86rc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rxkrDXLcZ3W2wzUrpwm5zSK86rc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rxkrDXLcZ3W2wzUrpwm5zSK86rc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rxkrDXLcZ3W2wzUrpwm5zSK86rc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/tMvbha2RnPE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/8784433998371889185/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=8784433998371889185" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/8784433998371889185" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/8784433998371889185" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/tMvbha2RnPE/binding-datagridview-combobox-column.html" title="Binding DataGridView ComboBox Column" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_HfnUI4smnYA/SMy9zcVAwyI/AAAAAAAAAF0/l4XCC6_EyXQ/s72-c/OrderForm.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/09/binding-datagridview-combobox-column.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-5296639869596996619</id><published>2008-09-11T10:36:00.003+06:00</published><updated>2008-10-24T11:52:03.336+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="How To" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Intermediate Topics" /><category scheme="http://www.blogger.com/atom/ns#" term="Crystal Reports" /><title type="text">How to handle Overlapping of Large Text Fields in Crystal Reports</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Intermediate&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;Crystal Reports&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;While working in Crystal Reports, we sometimes face a scenario when we need to put a Large Text Field (which can grow upto multiple lines). The issue comes if we try to put another Field after this Text Field. Example:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_HfnUI4smnYA/SMijXfcOZeI/AAAAAAAAAFM/buhQ2-X7xbE/s1600-h/CrystalReportsFieldsTogethe.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_HfnUI4smnYA/SMijXfcOZeI/AAAAAAAAAFM/buhQ2-X7xbE/s320/CrystalReportsFieldsTogethe.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5244621390045144546" /&gt;&lt;/a&gt;&lt;br /&gt;As you can see in above I have put to Formula Fields, both will contain Large Text which may expand. So here is the preview,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_HfnUI4smnYA/SMilEf0fjtI/AAAAAAAAAFU/6LBHcS8hDIg/s1600-h/CrystalReportsFieldsTogetherPreview.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_HfnUI4smnYA/SMilEf0fjtI/AAAAAAAAAFU/6LBHcS8hDIg/s320/CrystalReportsFieldsTogetherPreview.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5244623262752673490" /&gt;&lt;/a&gt;&lt;br /&gt;Therefore to solve this issue we can create multiple &lt;strong&gt;sub-sections in the same section&lt;/strong&gt;. This can be achieved by Section Expert.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_HfnUI4smnYA/SMil3E56fBI/AAAAAAAAAFc/8socG21xJos/s1600-h/CrystalReportsSectionExpert.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_HfnUI4smnYA/SMil3E56fBI/AAAAAAAAAFc/8socG21xJos/s320/CrystalReportsSectionExpert.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5244624131700980754" /&gt;&lt;/a&gt;&lt;br /&gt;Now we will put the Fields in different sub-sections as,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_HfnUI4smnYA/SMimjVnPVaI/AAAAAAAAAFk/QFm6XOQW1L8/s1600-h/CrystalReportsFieldsSection.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_HfnUI4smnYA/SMimjVnPVaI/AAAAAAAAAFk/QFm6XOQW1L8/s320/CrystalReportsFieldsSection.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5244624892100302242" /&gt;&lt;/a&gt;&lt;br /&gt;And here is the preview again,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_HfnUI4smnYA/SMioC8Hw6OI/AAAAAAAAAFs/iKfB9d3mu9I/s1600-h/CrsytalReportsFieldsSectionPreview.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_HfnUI4smnYA/SMioC8Hw6OI/AAAAAAAAAFs/iKfB9d3mu9I/s320/CrsytalReportsFieldsSectionPreview.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5244626534524840162" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Note that in Crystal Reports Sections automatically expand, that is why when the first Text Field expands, the section also expands itself, therefore ultimately the next field renders properly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-5296639869596996619?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6AEJjl1Nupt3xELH4xtkD1ENHrA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6AEJjl1Nupt3xELH4xtkD1ENHrA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6AEJjl1Nupt3xELH4xtkD1ENHrA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6AEJjl1Nupt3xELH4xtkD1ENHrA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/sU8c2tC3YRU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/5296639869596996619/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=5296639869596996619" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5296639869596996619" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5296639869596996619" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/sU8c2tC3YRU/how-to-handle-overlapping-of-large-text.html" title="How to handle Overlapping of Large Text Fields in Crystal Reports" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_HfnUI4smnYA/SMijXfcOZeI/AAAAAAAAAFM/buhQ2-X7xbE/s72-c/CrystalReportsFieldsTogethe.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/09/how-to-handle-overlapping-of-large-text.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-6302020754815978227</id><published>2008-09-04T13:18:00.004+06:00</published><updated>2008-10-07T12:08:13.920+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="DataGridView" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Intermediate Topics" /><title type="text">Using DataGridView CheckBox Column as RadioButton (OptionButton)</title><content type="html">&lt;a href="http://3.bp.blogspot.com/_HfnUI4smnYA/SL-Mj1VS48I/AAAAAAAAAE8/4nvEl5LJR9E/s1600-h/DGVCheckBoxAsRadioButtonForm.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_HfnUI4smnYA/SL-Mj1VS48I/AAAAAAAAAE8/4nvEl5LJR9E/s320/DGVCheckBoxAsRadioButtonForm.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5242063038522254274" /&gt;&lt;/a&gt;&lt;strong&gt;Level:&lt;/strong&gt; Beginner&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;DataGridView Control&lt;/li&gt;&lt;li&gt;Data Binding&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;In this post we shall see that how we can transform DataGridView control’s CheckBox column into Radio Button (option button).&lt;br /&gt;&lt;br /&gt;I have done 2 main things,&lt;ol&gt;&lt;li&gt;Created a back-end logic when user clicks on CheckBox Column so only one CheckBox should be checked at a time&lt;/li&gt;&lt;li&gt;Change the look of CheckBox column so it looks a Radio Button Column&lt;/li&gt;&lt;/ol&gt;So to understand the first one, consider a DataGridView control as shown in the above figure. This DataGridView control is actually bind with a DataSet for example,&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_HfnUI4smnYA/SL-M6rJVIyI/AAAAAAAAAFE/vRAYjFkyIyw/s1600-h/DGVCheckBoxDataSet.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_HfnUI4smnYA/SL-M6rJVIyI/AAAAAAAAAFE/vRAYjFkyIyw/s320/DGVCheckBoxDataSet.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5242063430924706594" /&gt;&lt;/a&gt;&lt;br /&gt;As you can see there are 2 columns. The &lt;strong&gt;IsSelected&lt;/strong&gt; column is actually a Boolean column which is normally rendered as CheckBox in DataGridView control. What we will be doing is that we first set our DataGridView to &lt;strong&gt;Read Only&lt;/strong&gt; i.e.,&lt;br /&gt;&lt;br /&gt;AllowUserToAddRows = False&lt;br /&gt;AllowUserToDeleteRows = False&lt;br /&gt;ReadOnly = True&lt;br /&gt;&lt;br /&gt;We are making our DataGridView control Read Only because it is easier to set the CheckBox checked or unchecked programmatically otherwise DataGridView control itself will be interfering and will create problems and complexities for us.&lt;br /&gt;&lt;br /&gt;OK now whenever user clicks on CheckBox we will be performing our custom operation. To do this we will use the DataGridView’s &lt;strong&gt;CellContentClick&lt;/strong&gt; event. Here is the code,&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; ShutDownOptionsDataGridView_CellContentClick(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; System.&lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.Windows.Forms.DataGridViewCellEventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; ShutDownOptionsDataGridView.CellContentClick&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; e.ColumnIndex = &lt;font color=blue&gt;Me&lt;/font&gt;.columnIsSelected.Index &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; drv &lt;font color=blue&gt;As&lt;/font&gt; DataRowView&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; rowShutDownOption &lt;font color=blue&gt;As&lt;/font&gt; ShutdownOptionDataSet.ShutDownOptionsRow&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' in this event handler we know that which DataGridView's row is clicked&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' so we are going to extract out the actual DataTable's row which is&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' bind with this DataGridView's Row&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;drv = &lt;font color=blue&gt;CType&lt;/font&gt;(&lt;font color=blue&gt;Me&lt;/font&gt;.ShutDownOptionsDataGridView.Rows(e.RowIndex).DataBoundItem, DataRowView)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' get the DataTable's row&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rowShutDownOption = &lt;font color=blue&gt;CType&lt;/font&gt;(drv.Row, ShutdownOptionDataSet.ShutDownOptionsRow)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' get the row which is currently selected&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; rowCurrentlySelected() &lt;font color=blue&gt;As&lt;/font&gt; ShutdownOptionDataSet.ShutDownOptionsRow&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rowCurrentlySelected = &lt;font color=blue&gt;Me&lt;/font&gt;.ShutdownOptionDataSet.ShutDownOptions.&lt;font color=blue&gt;Select&lt;/font&gt;(&lt;font color=darkred&gt;&amp;quot;IsSelected=True&amp;quot;&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' if some row found then make it de-selected&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; rowCurrentlySelected.Length &amp;gt; 0 &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rowCurrentlySelected(0).IsSelected = &lt;font color=blue&gt;False&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' ok now select the row which is clicked&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rowShutDownOption.IsSelected = &lt;font color=blue&gt;True&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;What we do is first get the row in which &lt;strong&gt;IsSelected=True&lt;/strong&gt; and we make that row &lt;strong&gt;IsSelected=False&lt;/strong&gt;. Then we set the row which is clicked as &lt;strong&gt;IsSelected=True&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;Next thing is to change the look of CheckBox to OptionButton / RadioButton. For this purpose we will be using DataGridView’s &lt;strong&gt;CellPainting&lt;/strong&gt; event. Here is the code,&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; ShutDownOptionsDataGridView_CellPainting(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.Windows.Forms.DataGridViewCellPaintingEventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; ShutDownOptionsDataGridView.CellPainting&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; e.ColumnIndex = &lt;font color=blue&gt;Me&lt;/font&gt;.columnIsSelected.Index &lt;font color=blue&gt;AndAlso&lt;/font&gt; _&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.RowIndex &amp;gt;= 0 &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.PaintBackground(e.ClipBounds, &lt;font color=blue&gt;True&lt;/font&gt;)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; rectRadioButton &lt;font color=blue&gt;As&lt;/font&gt; Rectangle&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rectRadioButton.Width = 14&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rectRadioButton.Height = 14&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rectRadioButton.X = e.CellBounds.X + (e.CellBounds.Width - rectRadioButton.Width) / 2&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rectRadioButton.Y = e.CellBounds.Y + (e.CellBounds.Height - rectRadioButton.Height) / 2&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; IsDBNull(e.Value) &lt;font color=blue&gt;OrElse&lt;/font&gt; e.Value = &lt;font color=blue&gt;False&lt;/font&gt; &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ControlPaint.DrawRadioButton(e.Graphics, rectRadioButton, ButtonState.Normal)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Else&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ControlPaint.DrawRadioButton(e.Graphics, rectRadioButton, ButtonState.Checked)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.Paint(e.ClipBounds, DataGridViewPaintParts.Focus)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.Handled = &lt;font color=blue&gt;True&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;As you can see we have used the &lt;strong&gt;ControlPaint&lt;/strong&gt; class to draw the RadioButton / OptionButton.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Download:&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://cid-c23746227866488d.skydrive.live.com/self.aspx/Public/DGVCheckBoxAsRadioButton.zip"&gt;DGVCheckBoxAsRadioButton.zip&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-6302020754815978227?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/nc0oWVCC-uz46ThEC_0oi1Cnsno/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nc0oWVCC-uz46ThEC_0oi1Cnsno/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/nc0oWVCC-uz46ThEC_0oi1Cnsno/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nc0oWVCC-uz46ThEC_0oi1Cnsno/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/YsPv2S-IygE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/6302020754815978227/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=6302020754815978227" title="10 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/6302020754815978227" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/6302020754815978227" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/YsPv2S-IygE/using-datagridview-checkbox-column-as.html" title="Using DataGridView CheckBox Column as RadioButton (OptionButton)" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_HfnUI4smnYA/SL-Mj1VS48I/AAAAAAAAAE8/4nvEl5LJR9E/s72-c/DGVCheckBoxAsRadioButtonForm.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">10</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/09/using-datagridview-checkbox-column-as.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-1510277354323481896</id><published>2008-09-03T11:42:00.004+06:00</published><updated>2008-11-22T12:45:15.460+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Threading" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Intermediate Topics" /><category scheme="http://www.blogger.com/atom/ns#" term="BackgroundWorker" /><category scheme="http://www.blogger.com/atom/ns#" term="Asynchronous Working" /><title type="text">Asynchronous Data Loading using TableAdapter with Cancel Feature</title><content type="html">&lt;span style="font-weight:bold;"&gt;Level:&lt;/span&gt; Intermediate&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Knowledge Required:&lt;/span&gt;&lt;ul&gt;&lt;li&gt;BackgroundWorker Control&lt;/li&gt;&lt;li&gt;DataGridView Control&lt;/li&gt;&lt;li&gt;Data Binding&lt;/li&gt;&lt;li&gt;TableAdapter&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight:bold;"&gt;Description:&lt;/span&gt;&lt;br /&gt;In my previous post&lt;br /&gt;&lt;br /&gt;&lt;a href="http://arsalantamiz.blogspot.com/2008/07/implement-sqlcommand-cancel-with.html"&gt;Implement SQLCommand Cancel with Threading&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have discussed how to implement the SQLCommand Cancel using Threading. In this post we shall see, how we can implement the same feature in a TableAdapter.&lt;br /&gt;&lt;br /&gt;As we know that TableAdapter is used as a middle level man standing between Physical Database and Typed DataSet. Which gets the data from Physical Database and loads into Typed DataSet. Sometimes this loading of data takes time (for example due to complex query). Therefore we can provide the user an ability to cancel the on going command by clicking on Cancel Button.&lt;br /&gt;&lt;br /&gt;I have created a Test Database (TestDB) and have added a table (tbl_Student). Also I have added a Stored Procedure (GetStudent). Take a look at this Stored Procedure:&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;CREATE PROCEDURE&lt;/font&gt; [dbo].[GetStudent] &lt;br /&gt;&lt;font color=blue&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;    SET NOCOUNT ON&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;font color=green&gt;-- here we are simulating a very long query&lt;br /&gt;    -- which takes 3 seconds to complete&lt;/font&gt;&lt;br /&gt;    &lt;font color=blue&gt;WAITFOR DELAY&lt;/font&gt; &lt;font color=darkred&gt;'00:00:03'&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;font color=blue&gt;SELECT&lt;/font&gt; *&lt;br /&gt;    &lt;font color=blue&gt;FROM&lt;/font&gt; tbl_Student;&lt;br /&gt;&lt;font color=blue&gt;END&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In this procedure I have added a &lt;span style="font-weight:bold;"&gt;WAITFOR DELAY&lt;/span&gt; SQL Statement. Which simulates a long query that takes time 3 seconds. We will call this procedure from our TableAdapter to fill the DataTable.&lt;br /&gt;&lt;br /&gt;Now we will add the SQLCommand Cancel stuff in our TableAdapter. This can be achieved by creating a Partial Class of TableAdapter,&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Namespace&lt;/font&gt; TestDataSetTableAdapters&lt;br /&gt;    &lt;font color=blue&gt;Partial Class&lt;/font&gt; StudentTableAdapter&lt;br /&gt;        &lt;font color=blue&gt;Public Sub&lt;/font&gt; CancelSelect()&lt;br /&gt;            &lt;font color=blue&gt;Me&lt;/font&gt;.Adapter.SelectCommand.Cancel()&lt;br /&gt;        &lt;font color=blue&gt;End Sub&lt;br /&gt;    End Class&lt;br /&gt;End Namespace&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As you see I have given the name of method &lt;span style="font-weight:bold;"&gt;CancelSelect&lt;/span&gt; which actually cancels the SelectCommand of Adapter. Note that I haven’t implemented any checking here (for example is command executing or NOT). This is upto the user of TableAdapter class. He/She will be responsible to check before executing this method.&lt;br /&gt;&lt;br /&gt;Here we have done with our TableAdapter. Now next thing is to implement the loading in the different Thread. For this purpose I have used the BackgroundWorker control which is quite simple. The overall idea is,&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Create 2 buttons&lt;/li&gt;&lt;ul&gt;&lt;li&gt;LoadButton&lt;/li&gt;&lt;li&gt;CancelButton&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;When LoadButton is clicked&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Execute the BackgroundWorker&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;In BackgroundWorker DoWork Event Handler&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Note somewhere that Execution is started&lt;/li&gt;&lt;li&gt;Execute the Fill() Method of TableAdapter&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;When CancelButton is clicked&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Check if execution is started then&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Execute the CancelSelect() method of TableAdapter&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Update Sep-4-2008:&lt;/span&gt;&lt;br /&gt;Here is the code of &lt;span style="font-weight:bold;"&gt;Form1&lt;/span&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Public&lt;/font&gt; &lt;font color=blue&gt;Class&lt;/font&gt; Form1&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' ErrorText will contain the error information if occurred&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' while loading data in different thread&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Private&lt;/font&gt; _ErrorText &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;String&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' this boolean variable will be true when command is executed&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Private&lt;/font&gt; _CommandExecuted &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Boolean&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; btnLoad_Click(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; System.&lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.EventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; btnLoad.Click&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' first we will disable the Load button so it should NOT be clicked again&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.btnLoad.Enabled = &lt;font color=blue&gt;False&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' then we will enable the Cancel button so the command can be canceled&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.btnCancel.Enabled = &lt;font color=blue&gt;True&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' set the status text&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Call&lt;/font&gt; &lt;font color=blue&gt;Me&lt;/font&gt;.SetStatusText(&lt;font color=darkred&gt;&amp;quot;Loading...&amp;quot;&lt;/font&gt;)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' clear the Error Text&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;._ErrorText = &lt;font color=darkred&gt;&amp;quot;&amp;quot;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' here we have first clear the currently loaded data&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' from DataSet, because the Adapter will fill the DataSet&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' in different thread, therefore it will create problems&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' while displaying the same data (which is being modified&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' in different thread) in DataGridView&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.TestDataSet.Clear()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' start the asynchronous task&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.BackgroundWorker1.RunWorkerAsync()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; BackgroundWorker1_DoWork(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.ComponentModel.DoWorkEventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; BackgroundWorker1.DoWork&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Try&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' first set the executed flag&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;._CommandExecuted = &lt;font color=blue&gt;True&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' execute the command&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.StudentTableAdapter.Fill(&lt;font color=blue&gt;Me&lt;/font&gt;.TestDataSet.Student)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Catch&lt;/font&gt; ex &lt;font color=blue&gt;As&lt;/font&gt; Exception&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_ErrorText = ex.Message&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Try&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; BackgroundWorker1_RunWorkerCompleted(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.ComponentModel.RunWorkerCompletedEventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; BackgroundWorker1.RunWorkerCompleted&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' ok our data is loaded now&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' so enable the Load button&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.btnLoad.Enabled = &lt;font color=blue&gt;True&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' disable the Cancel button&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.btnCancel.Enabled = &lt;font color=blue&gt;False&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' if NO error was occurred in thread&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; &lt;font color=blue&gt;Me&lt;/font&gt;._ErrorText = &lt;font color=darkred&gt;&amp;quot;&amp;quot;&lt;/font&gt; &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.SetStatusText(&lt;font color=blue&gt;Me&lt;/font&gt;.TestDataSet.Student.Count &amp;amp; &lt;font color=darkred&gt;&amp;quot; Records loaded&amp;quot;&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Else&lt;/font&gt; &lt;font color=green&gt;' else (some error was occurred)&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.SetStatusText(&lt;font color=blue&gt;Me&lt;/font&gt;._ErrorText)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' since data is changed in different thread&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' therefore by reseting the Bindings the DataGridView&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' will refresh itself and will display all the data&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.StudentBindingSource.ResetBindings(&lt;font color=blue&gt;False&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; btnCancel_Click(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; System.&lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.EventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; btnCancel.Click&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' if command is executed then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; &lt;font color=blue&gt;Me&lt;/font&gt;._CommandExecuted &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' cancel it&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.StudentTableAdapter.CancelSelect()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; SetStatusText(&lt;font color=blue&gt;ByVal&lt;/font&gt; sText &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;String&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.lblStatus.Text = sText&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Class&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Download:&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://cid-c23746227866488d.skydrive.live.com/self.aspx/Public/TableAdapterWithCancel.zip"&gt;TableAdapterWithCancel.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Note: The zip file contains &lt;strong&gt;TestDBScript.sql&lt;/strong&gt; T-SQL Script which will,&lt;br /&gt;1) Create a database "TestDB"&lt;br /&gt;2) Create a table "tbl_Student" in that database&lt;br /&gt;3) Create a Stored Procedure "GetStudent"&lt;br /&gt;4) Put some data in tbl_Student&lt;br /&gt;&lt;br /&gt;Please execute this script before running the project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-1510277354323481896?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/U-EdoUtIeXvXEQIB8xLj7Zbge2Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/U-EdoUtIeXvXEQIB8xLj7Zbge2Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/U-EdoUtIeXvXEQIB8xLj7Zbge2Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/U-EdoUtIeXvXEQIB8xLj7Zbge2Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/cQvjkmXiWi4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/1510277354323481896/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=1510277354323481896" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/1510277354323481896" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/1510277354323481896" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/cQvjkmXiWi4/asynchronous-data-loading-using.html" title="Asynchronous Data Loading using TableAdapter with Cancel Feature" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/09/asynchronous-data-loading-using.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-9147324614437333336</id><published>2008-08-12T13:02:00.000+06:00</published><updated>2008-10-07T12:08:13.918+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="ADO.net" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005" /><title type="text">Query Timeout in ADO.Net but NOT in SQL Server Management Studio</title><content type="html">I was facing this issue for a while that I have created a Stored Procedure in SQL Server 2005 Database that performs a search on a table (according to the given parameters). It was happening that when this procedure was executed from ADO.net (my front-end Visual Basic Application) Timeout exception was occurring. But at the same time when we execute this procedure from SQL Server Management Studio it executes immediately.&lt;br /&gt;&lt;br /&gt;The Timeout in Visual Basic Application was NOT coming immediately it was coming after some time when users execute the procedure many times. Whenever time out occurred, I went in the SQL Server Management Studio and just did ALTER (without changing a single thing in procedure). And the problem resolved for some time NOT permanently.&lt;br /&gt;&lt;br /&gt;So I put this question on MSDN Forums and a member told me to put the &lt;strong&gt;WITH RECOMPILE&lt;/strong&gt; in the procedure. He told me that&lt;br /&gt;&lt;br /&gt;"I think the problem is with the cache. When you ALTER the procedure from Management Studio it is recompiled and the problem is fixed. this is my guess."&lt;br /&gt;&lt;br /&gt;It sure fixed my problem and the Timeout never came afterwords. Here is the link to that post.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3068506&amp;SiteID=1&amp;pageid=0"&gt;http://forums.microsoft.com/MSDN/ShowPost.aspx...&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-9147324614437333336?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4-K36fghKRDSNEc3TQ7DYkuEr_0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4-K36fghKRDSNEc3TQ7DYkuEr_0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4-K36fghKRDSNEc3TQ7DYkuEr_0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4-K36fghKRDSNEc3TQ7DYkuEr_0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/RXiDt_y17pE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/9147324614437333336/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=9147324614437333336" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/9147324614437333336" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/9147324614437333336" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/RXiDt_y17pE/query-timeout-in-adonet-but-not-in-sql.html" title="Query Timeout in ADO.Net but NOT in SQL Server Management Studio" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/08/query-timeout-in-adonet-but-not-in-sql.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-3164835046726435217</id><published>2008-07-30T12:11:00.006+06:00</published><updated>2008-10-07T12:08:13.876+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Beginner Topics" /><category scheme="http://www.blogger.com/atom/ns#" term="ADO.net" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">Another look at Exception Handling</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Beginner&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;Exception Handling&lt;/li&gt;&lt;li&gt;ADO.net&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;As we have used the Exception Handling (Try...Catch) many times. But in this post we shall understand an important aspect. Consider the following code,&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; InsertSomeData()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; conn &lt;font color=blue&gt;As&lt;/font&gt; SqlClient.SqlConnection = &lt;font color=blue&gt;Nothing&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; cmd &lt;font color=blue&gt;As&lt;/font&gt; SqlClient.SqlCommand&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; tran &lt;font color=blue&gt;As&lt;/font&gt; SqlClient.SqlTransaction = &lt;font color=blue&gt;Nothing&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Try&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' initialize connection&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn = &lt;font color=blue&gt;New&lt;/font&gt; SqlClient.SqlConnection(&lt;font color=darkred&gt;&amp;quot;Data Source=.;Initial Catalog=MyDatabase;Integrated Security=True&amp;quot;&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' open connection&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn.Open()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' begin transaction&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tran = conn.BeginTransaction&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' create a Command&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cmd = conn.CreateCommand()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' setup command to insert data in 1st table&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cmd.CommandText = &lt;font color=darkred&gt;&amp;quot;INSERT INTO MyTable1(Column1) VALUES('Data in MyTable1.Column1')&amp;quot;&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cmd.ExecuteNonQuery()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' setup command to insert data in 2nd table&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cmd.CommandText = &lt;font color=darkred&gt;&amp;quot;INSERT INTO MyTable2(Column1) VALUES('Data in MyTable2.Column1')&amp;quot;&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cmd.ExecuteNonQuery()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' ok now commit the changes&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tran.Commit()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Catch&lt;/font&gt; ex &lt;font color=blue&gt;As&lt;/font&gt; Exception&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' an exception is occurred&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' check if transaction has been initialized then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp&lt;font color=green&gt;' rollback&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; tran &lt;font color=blue&gt;IsNot&lt;/font&gt; &lt;font color=blue&gt;Nothing&lt;/font&gt; &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tran.Rollback()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' again throw the exception&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' this is because we want the caller to be notified&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Throw&lt;/font&gt; ex&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Finally&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' finally block will be executed anyway&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' whether the exception is occurred or NOT&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' ================---------------------&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' Note: we are again throwing the exception in Catch block &lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; but still the following code will be executed&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; conn &lt;font color=blue&gt;IsNot&lt;/font&gt; &lt;font color=blue&gt;Nothing&lt;/font&gt; &lt;font color=blue&gt;AndAlso&lt;/font&gt; _&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.State = ConnectionState.Open &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' if connection was established then close it&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn.Close()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' =====================-------------------------&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Try&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' this line however will NOT be executed if&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=green&gt;' exception is occurred&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.Print(&lt;font color=darkred&gt;&amp;quot;Outside the Try..Catch block&amp;quot;&lt;/font&gt;)&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;As you can see this method will be inserting data in 2 tables. Our goal is,&lt;br /&gt;&lt;br /&gt;Begin the Transaction&lt;br /&gt;Try to Insert the Data in Tables&lt;br /&gt;If no error occurs on Insertion then Commit the Transaction&lt;br /&gt;If error occurred then &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Rollback the Transaction&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Again throw the Exception (so the caller is being notified)&lt;br /&gt;End If&lt;br /&gt;At the end (whether exception is occred or NOT) Close the connection&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color:lightyellow;"&gt;Note that if Exception occurs then in &lt;strong&gt;Catch block&lt;/strong&gt; we are &lt;strong&gt;throwing&lt;/strong&gt; the same exception again. At this point it seems that control will immediately &lt;strong&gt;exit&lt;/strong&gt; from this method, but fortunately this does NOT happen in this way. Instead control first jumps to &lt;strong&gt;Finally block&lt;/strong&gt; then after that it exits from method.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-3164835046726435217?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jgSb773lWUcn-utVxdVxBWbqP0c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jgSb773lWUcn-utVxdVxBWbqP0c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jgSb773lWUcn-utVxdVxBWbqP0c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jgSb773lWUcn-utVxdVxBWbqP0c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/C62oqT--emE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/3164835046726435217/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=3164835046726435217" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/3164835046726435217" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/3164835046726435217" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/C62oqT--emE/another-look-at-exception-handling.html" title="Another look at Exception Handling" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/07/another-look-at-exception-handling.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-5388667664678789958</id><published>2008-07-30T10:58:00.005+06:00</published><updated>2008-10-07T12:08:13.884+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Win Forms" /><category scheme="http://www.blogger.com/atom/ns#" term="Beginner Topics" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">Enter Key to Set Focus in Next Control (for Data Entry Forms)</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Beginner&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;Windows Forms&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;In a Windows Application, we use &lt;strong&gt;Tab&lt;/strong&gt; key to move Focus from current control to next control, but in a &lt;strong&gt;Data Entry&lt;/strong&gt; applications, usually &lt;strong&gt;Enter Key&lt;/strong&gt; is used for this purpose.&lt;br /&gt;&lt;br /&gt;There are different techniques to accomplish this. I think the following is the simplest one.&lt;br /&gt;&lt;br /&gt;First set the Form's &lt;strong&gt;KeyPreview&lt;/strong&gt; property to True. Then put the following code in the KeyPress Event Handler:&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; Form1_KeyPress(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; &lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.Windows.Forms.KeyPressEventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; &lt;font color=blue&gt;Me&lt;/font&gt;.KeyPress&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; e.KeyChar = Chr(Keys.Return) &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Me&lt;/font&gt;.SelectNextControl(&lt;font color=blue&gt;Me&lt;/font&gt;.ActiveControl, &lt;font color=blue&gt;True&lt;/font&gt;, &lt;font color=blue&gt;True&lt;/font&gt;, &lt;font color=blue&gt;True&lt;/font&gt;, &lt;font color=blue&gt;True&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-5388667664678789958?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Orlu8_0ul1uUoMB2QT9550xi9yg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Orlu8_0ul1uUoMB2QT9550xi9yg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Orlu8_0ul1uUoMB2QT9550xi9yg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Orlu8_0ul1uUoMB2QT9550xi9yg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/_2xcVCqwBRo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/5388667664678789958/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=5388667664678789958" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5388667664678789958" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5388667664678789958" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/_2xcVCqwBRo/enter-key-to-set-focus-in-next-control.html" title="Enter Key to Set Focus in Next Control (for Data Entry Forms)" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/07/enter-key-to-set-focus-in-next-control.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-1480049484326053588</id><published>2008-07-29T13:30:00.010+06:00</published><updated>2008-11-22T12:44:47.972+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Threading" /><category scheme="http://www.blogger.com/atom/ns#" term="ADO.net" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Advanced Topics" /><category scheme="http://www.blogger.com/atom/ns#" term="Asynchronous Working" /><title type="text">Implement SQLCommand Cancel with Threading</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Advanced&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;ADO.net&lt;/li&gt;&lt;li&gt;Threading&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;In a data driven application, sometimes we built queries which take time. In these type of scenarios usually developers put the query execution on different thread, so the User Interface keep responsive.&lt;br /&gt;&lt;br /&gt;A more user friendly applications provide a flexibility to cancel the currently executing command. This can be achieved by using &lt;strong&gt;SQLCommand.Cancel()&lt;/strong&gt; method.&lt;br /&gt;&lt;br /&gt;So to implement it, &lt;ul&gt;&lt;li&gt;Create a Thread&lt;/li&gt;&lt;li&gt;Execute Query in that Thread&lt;/li&gt;&lt;li&gt;Meanwhile if user clicks the Cancel button we will call the SQLCommand.Cancel method&lt;/li&gt;&lt;/ul&gt;Cancel method actually &lt;strong&gt;tries&lt;/strong&gt; to cancel the in-process query. When the attempt to cancel the query succeeds then an exception is occured at the same point where Command was executed i.e. SQLCommand.ExecuteReader (or other Execute method) was called. When the cancellation is failed then no exception occurs and command continues its execution. Therefore we also need to handle the Exception at the same point where we have executed the query. Here is an example:&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; DoSomeWork()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;objCon = &lt;font color=blue&gt;New&lt;/font&gt; SqlConnection(&lt;font color=darkred&gt;&amp;quot;Data Source=.;Integrated Security=True&amp;quot;&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;objCmd = &lt;font color=blue&gt;New&lt;/font&gt; SqlCommand(&lt;font color=darkred&gt;&amp;quot;WAITFOR DELAY '00:00:05';&amp;quot;&lt;/font&gt;, objCon)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;objCon.Open()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Try&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;objCmd.ExecuteReader()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Catch&lt;/font&gt; ex &lt;font color=blue&gt;As&lt;/font&gt; SqlException&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.Print(ex.Message)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Try&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;objCon.Close()&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;The above method just executes a &lt;strong&gt;WAITFOR DELAY&lt;/strong&gt; query which simulates a very long query that takes 5 seconds to complete. Note that objCon and objCmd are Module Level variables. This method will be executed in a different thread using the following code,&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Dim&lt;/font&gt; t &lt;font color=blue&gt;As&lt;/font&gt; Threading.Thread&lt;br /&gt;t = &lt;font color=blue&gt;New&lt;/font&gt; Threading.Thread(&lt;font color=blue&gt;AddressOf&lt;/font&gt; DoSomeWork)&lt;br /&gt;t.Start()&lt;/pre&gt;&lt;br /&gt;While this query is being executed we will perform a query cancel on a button click event as,&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; CancelButton_Click(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; System.&lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.EventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; btnCancel.Click&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;If&lt;/font&gt; objCmd &lt;font color=blue&gt;IsNot&lt;/font&gt; &lt;font color=blue&gt;Nothing&lt;/font&gt; &lt;font color=blue&gt;Then&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;objCmd.Cancel()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;If&lt;/font&gt;&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;See Also:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://arsalantamiz.blogspot.com/2008/09/asynchronous-data-loading-using.html"&gt;Asynchronous Data Loading using TableAdapter with Cancel Feature&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-1480049484326053588?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dQU__Jc8n5qLFHCNgOxRF_y3iy8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dQU__Jc8n5qLFHCNgOxRF_y3iy8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dQU__Jc8n5qLFHCNgOxRF_y3iy8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dQU__Jc8n5qLFHCNgOxRF_y3iy8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/8atsROG__n0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/1480049484326053588/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=1480049484326053588" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/1480049484326053588" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/1480049484326053588" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/8atsROG__n0/implement-sqlcommand-cancel-with.html" title="Implement SQLCommand Cancel with Threading" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/07/implement-sqlcommand-cancel-with.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-4150134718809822743</id><published>2008-07-28T23:32:00.003+06:00</published><updated>2008-10-07T12:08:13.877+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Beginner Topics" /><category scheme="http://www.blogger.com/atom/ns#" term="Custom Controls" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">Draw Focus Rectangle using ControlPaint Class</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Beginner&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;GDI+&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;Sometimes while creating a User Control from scratch. It is required to display the Focus Rectangle (the dotted border). This can be easily achieved by using&lt;br /&gt;&lt;br /&gt;System.Windows.Forms.ControlPaint&lt;br /&gt;&lt;br /&gt;E.g.:&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;font color=blue&gt;Private&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt; Form1_Click(&lt;font color=blue&gt;ByVal&lt;/font&gt; sender &lt;font color=blue&gt;As&lt;/font&gt; System.&lt;font color=blue&gt;Object&lt;/font&gt;, &lt;font color=blue&gt;ByVal&lt;/font&gt; e &lt;font color=blue&gt;As&lt;/font&gt; System.EventArgs) &lt;font color=blue&gt;Handles&lt;/font&gt; &lt;font color=blue&gt;Me&lt;/font&gt;.Click&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=blue&gt;Dim&lt;/font&gt; g &lt;font color=blue&gt;As&lt;/font&gt; Graphics&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;g = &lt;font color=blue&gt;Me&lt;/font&gt;.CreateGraphics&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ControlPaint.DrawFocusRectangle(g, &lt;font color=blue&gt;New&lt;/font&gt; Rectangle(10, 10, 100, 100))&lt;br /&gt;&lt;font color=blue&gt;End&lt;/font&gt; &lt;font color=blue&gt;Sub&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;ControlPaint class contains other useful routines for control drawing you can explore the list using intellisense.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-4150134718809822743?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ntoAdQrvP3FFqK1EvrrISpnGC20/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ntoAdQrvP3FFqK1EvrrISpnGC20/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ntoAdQrvP3FFqK1EvrrISpnGC20/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ntoAdQrvP3FFqK1EvrrISpnGC20/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/v0Qtt9K2DQc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/4150134718809822743/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=4150134718809822743" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/4150134718809822743" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/4150134718809822743" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/v0Qtt9K2DQc/draw-focus-rectangle-using-controlpaint.html" title="Draw Focus Rectangle using ControlPaint Class" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/07/draw-focus-rectangle-using-controlpaint.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-7473703406743809882</id><published>2008-07-26T16:47:00.002+06:00</published><updated>2008-10-07T12:08:13.916+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Beginner Topics" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.net" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">Dynamically Loading Data in TreeView control ASP.net</title><content type="html">&lt;strong&gt;Level:&lt;/strong&gt; Beginner&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;ASP.net&lt;/li&gt;&lt;li&gt;Typed DataSet&lt;/li&gt;&lt;li&gt;TableAdapter&lt;/li&gt;&lt;li&gt;SQL Server 2005&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;In my post &lt;a href="http://arsalantamiz.blogspot.com/2008/06/dynamically-loading-data-in-treeview.html"&gt;Dynamically Loading Data in TreeView Control&lt;/a&gt;, I have discussed how to load the data on runtime in TreeView control. This post is for Windows Application (Windows Forms) platform. Recently I was asked to have the same code for ASP.net Web Application. I think there are lots of articles available on Internet about this kind of stuff. But I am also submitting my own.&lt;br /&gt;&lt;br /&gt;This is a very simple project demonstrates how to dynamically load data when TreeView's Node is expanded.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Download:&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://cid-c23746227866488d.skydrive.live.com/self.aspx/Public/DynamicTreeview.zip"&gt;DynamicTreeview.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Note: The zip file contains &lt;strong&gt;DynamicTreeViewDatabaseSetup.sql&lt;/strong&gt; T-SQL Script which will,&lt;br /&gt;1) Create a database "MyDatabase"&lt;br /&gt;2) Create a table "tbl_Category" in that database&lt;br /&gt;3) Create a Stored Procedure "CategorySelect"&lt;br /&gt;4) Put some data in tbl_Category&lt;br /&gt;&lt;br /&gt;Please execute this script before running the project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-7473703406743809882?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LAvdALUu-vA-XRfM5X4OtopUB80/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LAvdALUu-vA-XRfM5X4OtopUB80/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LAvdALUu-vA-XRfM5X4OtopUB80/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LAvdALUu-vA-XRfM5X4OtopUB80/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/2envdTgnO5U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/7473703406743809882/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=7473703406743809882" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/7473703406743809882" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/7473703406743809882" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/2envdTgnO5U/dynamically-loading-data-in-treeview.html" title="Dynamically Loading Data in TreeView control ASP.net" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/07/dynamically-loading-data-in-treeview.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-3227807731981346632</id><published>2008-07-19T15:08:00.007+06:00</published><updated>2008-10-07T12:08:13.893+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Useful Functions" /><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Intermediate Topics" /><title type="text">Function to Trim any Character/String from Left of varchar in SQL Server</title><content type="html">An Extended Left Trim (LTRIM) Function for SQL Server which removes given string/character from Left of another varchar (String)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Level:&lt;/strong&gt; Intermediate&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;T-SQL&lt;/li&gt;&lt;li&gt;SQL Server 2005&lt;/li&gt;&lt;li&gt;SQL Server User Define Functions&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;The SQL Server's built-in &lt;strong&gt;LTrim()&lt;/strong&gt; function removes &lt;strong&gt;only&lt;/strong&gt; the blanks (spaces) from Left of a varchar (string). Here is a User Defined function which can remove &lt;strong&gt;any&lt;/strong&gt; character.&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;span style="color:blue;"&gt;CREATE FUNCTION&lt;/span&gt; [dbo].[LTrimString]&lt;br /&gt;(&lt;br /&gt; &lt;span style="color:green;"&gt;-- Add the parameters for the function here&lt;/span&gt;&lt;br /&gt; @StringToTrim &lt;span style="color:blue;"&gt;varchar&lt;/span&gt;(&lt;span style="color:magenta;"&gt;max&lt;/span&gt;),&lt;br /&gt; @CharToTrim &lt;span style="color:blue;"&gt;varchar&lt;/span&gt;(10)&lt;br /&gt;)&lt;br /&gt;&lt;span style="color:blue;"&gt;RETURNS varchar&lt;/span&gt;(&lt;span style="color:magenta;"&gt;max&lt;/span&gt;)&lt;br /&gt;&lt;span style="color:blue;"&gt;AS&lt;br /&gt;BEGIN&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;-- Declare the return variable here&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt; @Result &lt;span style="color:blue;"&gt;varchar&lt;/span&gt;(&lt;span style="color:magenta;"&gt;max&lt;/span&gt;);&lt;br /&gt;    &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt; @i &lt;span style="color:blue;"&gt;int&lt;/span&gt;;&lt;br /&gt;    &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt; @l &lt;span style="color:blue;"&gt;int&lt;/span&gt;;&lt;br /&gt;    &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt; @sl &lt;span style="color:blue;"&gt;int&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;SET&lt;/span&gt; @i = 1;&lt;br /&gt;    &lt;span style="color:blue;"&gt;SET&lt;/span&gt; @l = &lt;span style="color:magenta;"&gt;Len&lt;/span&gt;(@StringToTrim);&lt;br /&gt;    &lt;span style="color:blue;"&gt;SET&lt;/span&gt; @sl = &lt;span style="color:magenta;"&gt;Len&lt;/span&gt;(@CharToTrim);&lt;br /&gt;    &lt;span style="color:blue;"&gt;While&lt;/span&gt; @i &lt; @l&lt;br /&gt;    &lt;span style="color:blue;"&gt;Begin  &lt;br /&gt;            If&lt;/span&gt; SubString(@StringToTrim, @i, @sl) &lt;&gt; @CharToTrim&lt;br /&gt;            &lt;span style="color:blue;"&gt;Begin&lt;/span&gt;&lt;br /&gt;                &lt;span style="color:blue;"&gt;SET&lt;/span&gt; @Result = &lt;span style="color:magenta;"&gt;SubString&lt;/span&gt;(@StringToTrim, @i, @l - @i + 1);&lt;br /&gt;                &lt;span style="color:blue;"&gt;Break&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color:blue;"&gt;End&lt;br /&gt;        SET&lt;/span&gt; @i = @i + @sl;&lt;br /&gt;    &lt;span style="color:blue;"&gt;End&lt;br /&gt;&lt;br /&gt;    SET&lt;/span&gt; @Result = &lt;span style="color:magenta;"&gt;IsNull&lt;/span&gt;(@Result, @StringToTrim);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;-- Return the result of the function&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt; @Result;&lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;span style="color:blue;"&gt;Print&lt;/span&gt; dbo.LTrimString(&lt;span style="color:red;"&gt;'00000005221'&lt;/span&gt;, &lt;span style="color:red;"&gt;'0'&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;Output:&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;5221&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-3227807731981346632?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_Lf4mF16JYvuVwGBVEtmhYPXGY0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_Lf4mF16JYvuVwGBVEtmhYPXGY0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_Lf4mF16JYvuVwGBVEtmhYPXGY0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_Lf4mF16JYvuVwGBVEtmhYPXGY0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/3p5S8XyVEZ4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/3227807731981346632/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=3227807731981346632" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/3227807731981346632" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/3227807731981346632" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/3p5S8XyVEZ4/function-to-trim-any-characterstring.html" title="Function to Trim any Character/String from Left of varchar in SQL Server" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/07/function-to-trim-any-characterstring.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-6799055193410467526</id><published>2008-07-17T00:07:00.007+06:00</published><updated>2008-10-07T12:08:13.913+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Regular Expression" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Intermediate Topics" /><title type="text">Replace with Regular Expression</title><content type="html">This article explains some outstanding usage of Regular Expression's &lt;strong&gt;Replace&lt;/strong&gt; Method&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Level:&lt;/strong&gt; Intermediate&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;Regular Expressions&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;Currently I am working on a Tool (Short Project) to convert the code into HTML. This is my requirement, since it takes time to convert the code into HTML format, before I can paste into Blogger.&lt;br /&gt;&lt;br /&gt;So I will be heavily using Regular Expression (RegEx Class) in this project. Meanwhile I am sharing the core technique here.&lt;br /&gt;&lt;br /&gt;In code we use &lt;strong&gt;Keywords&lt;/strong&gt;, words that highlight with different color. For example "Dim", "Me", "As", "For", etc. I use "span" or "font" tag to change the text color. E.g.&lt;br /&gt;&lt;br /&gt;&amp;lt;span style="color:blue;"&amp;gt;Dim&amp;lt;/span&amp;gt;&lt;br /&gt;&lt;br /&gt;Usually keywords found to be separated with white-spaces,&lt;br /&gt;&lt;br /&gt;Dim myVar As String&lt;br /&gt;&lt;br /&gt;3 Keywords: Dim, As, String&lt;br /&gt;&lt;br /&gt;All of them are separated with Space. But some keywords are used as Instances,&lt;br /&gt;&lt;br /&gt;Me.TextBox1.Text = "ABC"&lt;br /&gt;&lt;br /&gt;Here "Me" has "." (full stop)&lt;br /&gt;&lt;br /&gt;As per above findings, I decided,&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color:lightyellow; padding=1em 1em 1em 1em"&gt;To Convert the Code into HTML replace the Keywords with the Tags&lt;/div&gt;&lt;br /&gt;&lt;strong&gt;Me.TextBox1.Text = "ABC"&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;we can replace the above line as,&lt;br /&gt;&lt;br /&gt;&amp;lt;span style="color:blue;"&amp;gt;Me&amp;lt;/span&amp;gt;.TextBox1.Text = "ABC"&lt;br /&gt;&lt;br /&gt;So here we are using the &lt;strong&gt;Replace&lt;/strong&gt;. Which gave me the idea to use the Regular Expression, because its Replace method is very flexible. First we need to decide the &lt;strong&gt;Pattern&lt;/strong&gt;. For the above case the pattern will be,&lt;br /&gt;&lt;br /&gt;(\W|^)(Me)(\W|$)&lt;br /&gt;&lt;br /&gt;In above statement &lt;strong&gt;()&lt;/strong&gt; brackets are indicating &lt;strong&gt;Groups&lt;/strong&gt;. Therefore in above pattern I have used 3 groups. Which we will be using in Replace String.&lt;br /&gt;&lt;br /&gt;Next we need to decide what should be the &lt;strong&gt;Replace&lt;/strong&gt; String.&lt;br /&gt;&lt;br /&gt;$1&amp;lt;font color=blue&amp;gt;$2&amp;lt;/font&amp;gt;$3&lt;br /&gt;&lt;br /&gt;The above string means that while replacing,&lt;br /&gt;&lt;br /&gt;1) Put Group #1&lt;br /&gt;2) Put Font Tag&lt;br /&gt;3) Put Group #2&lt;br /&gt;4) Close the Font Tag&lt;br /&gt;5) Put the Group #3&lt;br /&gt;&lt;br /&gt;That's it, here is the complete code,&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;span style="color:blue;"&gt;Dim&lt;/span&gt; sCode &lt;span style="color:blue;"&gt;As String&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;Dim&lt;/span&gt; sHTML &lt;span style="color:blue;"&gt;As String&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;sCode = &lt;span style="color:darkred;"&gt;"Me.TextBox1.Text=""Abc"""&lt;/span&gt;&lt;br /&gt;sHTML = System. _&lt;br /&gt;            Text. _&lt;br /&gt;                RegularExpressions. _&lt;br /&gt;                    Regex.Replace( _&lt;br /&gt;                                    sCode, _&lt;br /&gt;                                    &lt;span style="color:darkred;"&gt;"(\W|^)(Me)(\W|$)"&lt;/span&gt;, _&lt;br /&gt;                                    &lt;span style="color:darkred;"&gt;"$1&amp;lt;font color=blue&amp;gt;$2&amp;lt;/font&amp;gt;$3"&lt;/span&gt;, _&lt;br /&gt;                                    System.Text.RegularExpressions.RegexOptions.IgnoreCase _&lt;br /&gt;                                )&lt;br /&gt;Debug.Print(sHTML)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-6799055193410467526?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Mowxz1rYlEVtdV8ux5zuIdPjLms/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Mowxz1rYlEVtdV8ux5zuIdPjLms/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Mowxz1rYlEVtdV8ux5zuIdPjLms/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Mowxz1rYlEVtdV8ux5zuIdPjLms/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/V_cBY4AsyJE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/6799055193410467526/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=6799055193410467526" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/6799055193410467526" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/6799055193410467526" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/V_cBY4AsyJE/replace-with-regular-expression.html" title="Replace with Regular Expression" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/07/replace-with-regular-expression.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-6837250508009744375.post-5946372751960871615</id><published>2008-07-16T12:08:00.014+06:00</published><updated>2008-10-07T12:08:13.907+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="Win Forms" /><category scheme="http://www.blogger.com/atom/ns#" term="Beginner Topics" /><category scheme="http://www.blogger.com/atom/ns#" term="How To" /><category scheme="http://www.blogger.com/atom/ns#" term=".net 2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="VB 2005" /><title type="text">How to Pass Data Across Forms</title><content type="html">In this post we will discuss how can we share different variables among Forms.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Level:&lt;/strong&gt; Beginner&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Knowledge Required:&lt;/strong&gt;&lt;br /&gt;Win Forms&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;While creating a Windows Forms Application, we usually face a requirement when we need to pass one or more variables from one Form to another. For example, we have created a Dialog Box which takes Date Range,&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_HfnUI4smnYA/SH2RvDyZpTI/AAAAAAAAAEs/9R7ROPk6r9k/s1600-h/DateRangeDialog.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp0.blogger.com/_HfnUI4smnYA/SH2RvDyZpTI/AAAAAAAAAEs/9R7ROPk6r9k/s320/DateRangeDialog.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5223491380476224818" /&gt;&lt;/a&gt;&lt;br /&gt;When we display this dialog box, we want that a default date range should be given, also this dialog box should return the new Date Range that is selected.&lt;br /&gt;&lt;br /&gt;To pass the data to Form we can directly use Form's Control as, &lt;br /&gt;&lt;br /&gt;In Form1.Button1.Click Event Handler:&lt;br /&gt;&lt;br /&gt;DateRangeDialog.DateTimePicker1.Value = Now&lt;br /&gt;&lt;br /&gt;As you can see the above code, I have used the DateRangeDialog's DateTimePicker control in Form1's Button Click event Handler, but it is better to create &lt;strong&gt;Public Properties&lt;/strong&gt; on Form and use them. Also we can utilize the &lt;strong&gt;Constructor (New Method)&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;span style="color:blue;"&gt;Public Class&lt;/span&gt; dlgDateRange&lt;br /&gt;    &lt;span style="color:blue;"&gt;Private&lt;/span&gt; _DateStart &lt;span style="color:blue;"&gt;As Date&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;Private&lt;/span&gt; _DateEnd &lt;span style="color:blue;"&gt;As Date&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;'Public properties that will be used to get the selected dates&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;Public ReadOnly Property&lt;/span&gt; DateStart() &lt;span style="color:blue;"&gt;As Date&lt;br /&gt;        Get&lt;br /&gt;            Return Me&lt;/span&gt;._DateStart&lt;br /&gt;        &lt;span style="color:blue;"&gt;End Get&lt;br /&gt;    End Property&lt;br /&gt;&lt;br /&gt;    Public ReadOnly Property&lt;/span&gt; DateEnd() &lt;span style="color:blue;"&gt;As Date&lt;br /&gt;        Get&lt;br /&gt;            Return Me.&lt;/span&gt;_DateEnd&lt;br /&gt;        &lt;span style="color:blue;"&gt;End Get&lt;br /&gt;    End Property&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;' default constructor&lt;/span&gt;&lt;br /&gt;    Public Sub New&lt;/span&gt;()&lt;br /&gt;        &lt;span style="color:green;"&gt;' This call is required by the Windows Form Designer.&lt;/span&gt;&lt;br /&gt;        InitializeComponent()&lt;br /&gt;        &lt;span style="color:green;"&gt;' Add any initialization after the InitializeComponent() call.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;._DateStart = Now&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;._DateEnd = Now&lt;br /&gt;    &lt;span style="color:blue;"&gt;End Sub&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;' if dates are supplied on initializing&lt;/span&gt;&lt;br /&gt;    Public Sub New&lt;/span&gt;(&lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; DateStart &lt;span style="color:blue;"&gt;As Date&lt;/span&gt;, &lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; DateEnd &lt;span style="color:blue;"&gt;As Date&lt;/span&gt;)&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.New()&lt;br /&gt;        &lt;span style="color:green;"&gt;' Add any initialization after the InitializeComponent() call.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;._DateStart = DateStart&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;._DateEnd = DateEnd&lt;br /&gt;    &lt;span style="color:blue;"&gt;End Sub&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;' OK button is clicked&lt;/span&gt;&lt;br /&gt;    Private Sub&lt;/span&gt; OK_Button_Click(&lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color:blue;"&gt;As&lt;/span&gt; System.Object, &lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; e &lt;span style="color:blue;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color:blue;"&gt;Handles&lt;/span&gt; OK_Button.Click&lt;br /&gt;        &lt;span style="color:green;"&gt;' set the selected values and close dialog&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;._DateStart = &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.DateTimePicker1.Value&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;._DateEnd = &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.DateTimePicker2.Value&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.DialogResult = System.Windows.Forms.DialogResult.OK&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.Close()&lt;br /&gt;    &lt;span style="color:blue;"&gt;End Sub&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color:green;"&gt;' cancel button is clicked&lt;/span&gt;&lt;br /&gt;    Private Sub&lt;/span&gt; Cancel_Button_Click(&lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color:blue;"&gt;As&lt;/span&gt; System.Object, &lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; e &lt;span style="color:blue;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color:blue;"&gt;Handles&lt;/span&gt; Cancel_Button.Click&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.DialogResult = System.Windows.Forms.DialogResult.Cancel&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.Close()&lt;br /&gt;    &lt;span style="color:blue;"&gt;End Sub&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;' on form load event we will set the dates which were supplied on initializing&lt;/span&gt;&lt;br /&gt;    Private Sub&lt;/span&gt; dlgDateRange_Load(&lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color:blue;"&gt;As&lt;/span&gt; System.Object, &lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; e &lt;span style="color:blue;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color:blue;"&gt;Handles MyBase&lt;/span&gt;.Load&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.DateTimePicker1.Value = &lt;span style="color:blue;"&gt;Me&lt;/span&gt;._DateStart&lt;br /&gt;        &lt;span style="color:blue;"&gt;Me&lt;/span&gt;.DateTimePicker2.Value = &lt;span style="color:blue;"&gt;Me&lt;/span&gt;._DateEnd&lt;br /&gt;    &lt;span style="color:blue;"&gt;End Sub&lt;br /&gt;End Class&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;br /&gt;&lt;pre style="padding:1em 1em 1em 1em; overflow: auto; color: black;font-family:Monospace,Courier New,Courier;font-size:85%;background-color:whitesmoke;"&gt;&lt;span style="color:blue;"&gt;Dim&lt;/span&gt; dlgNew &lt;span style="color:blue;"&gt;As&lt;/span&gt; dlgDateRange&lt;br /&gt;dlgNew = &lt;span style="color:blue;"&gt;New&lt;/span&gt; dlgDateRange(&lt;span style="color:blue;"&gt;New Date&lt;/span&gt;(2008, 1, 1), &lt;span style="color:blue;"&gt;New Date&lt;/span&gt;(2008, 6, 30))&lt;br /&gt;&lt;span style="color:blue;"&gt;If&lt;/span&gt; dlgNew.ShowDialog() = Windows.Forms.DialogResult.OK &lt;span style="color:blue;"&gt;Then&lt;/span&gt;&lt;br /&gt;    Debug.Print(&lt;span style="color:darkred;"&gt;"Date Start: "&lt;/span&gt; &amp; dlgNew.DateStart)&lt;br /&gt;    Debug.Print(&lt;span style="color:darkred;"&gt;"Date End: "&lt;/span&gt; &amp; dlgNew.DateEnd)&lt;br /&gt;&lt;span style="color:blue;"&gt;End If&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6837250508009744375-5946372751960871615?l=arsalantamiz.blogspot.com'/&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0HA0P-QSDbHR3PK8dtBk7-k1KZM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0HA0P-QSDbHR3PK8dtBk7-k1KZM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0HA0P-QSDbHR3PK8dtBk7-k1KZM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0HA0P-QSDbHR3PK8dtBk7-k1KZM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/VisualBasicDevelopmentIssues/~4/cCaQJYSonV4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://arsalantamiz.blogspot.com/feeds/5946372751960871615/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6837250508009744375&amp;postID=5946372751960871615" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5946372751960871615" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6837250508009744375/posts/default/5946372751960871615" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/VisualBasicDevelopmentIssues/~3/cCaQJYSonV4/how-to-pass-data-across-forms.html" title="How to Pass Data Across Forms" /><author><name>Arsalan Tamiz</name><uri>http://www.blogger.com/profile/03883319971948565803</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="16485464690636427934" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://bp0.blogger.com/_HfnUI4smnYA/SH2RvDyZpTI/AAAAAAAAAEs/9R7ROPk6r9k/s72-c/DateRangeDialog.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://arsalantamiz.blogspot.com/2008/07/how-to-pass-data-across-forms.html</feedburner:origLink></entry></feed>
