<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://bloggingabout.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tag 'Code Samples'</title><link>http://bloggingabout.net/search/SearchResults.aspx?a=1&amp;o=DateDescending&amp;tag=Code+Samples&amp;orTags=0</link><description>Search results matching tag 'Code Samples'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>How to: Delete rows from a table using a join on a second table</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/10/22/how-to-delete-rows-from-a-table-using-a-join-on-a-second-table.aspx</link><pubDate>Wed, 22 Oct 2008 08:43:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:475821</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;In my current project, we have a tables where the primary key consists of two values. Based on the result of a query, we needed to delete a few rows from that table. The query returned the two key values and we needed to join that information in the delete statement. It&amp;#39;s not rocket science, but it did cost us some searching before we had a solution. To make sure I don&amp;#39;t forget, this small blog shows how we did it.&lt;/p&gt;
&lt;p&gt;First of all, when you need to delete information from one table based on information from a second, then this is the way to go:&lt;/p&gt;
&lt;div style="font-size:9pt;background:#f5f5f5;overflow:auto;width:100%;color:black;font-family:Courier New;border:#cccccc 1pt solid;padding:1pt;"&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;DELETE &lt;/span&gt;t1&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;FROM &lt;/span&gt;MyTable1 &lt;span style="color:#0000ff;"&gt;AS &lt;/span&gt;t1 &lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;inner join &lt;/span&gt;MYTABLE2 t2 &lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;ON &lt;/span&gt;t1.KeyValue1= t2.KeyValue1 &lt;span style="color:#0000ff;"&gt;and &lt;/span&gt;t1.KeyValue2 = t2.KeyValue2&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, you simply add the join and specify the key values for that join. However, we needed the result from a query. To do that, you can use the following solution:&lt;/p&gt;
&lt;div style="font-size:9pt;background:#f5f5f5;overflow:auto;width:100%;color:black;font-family:Courier New;border:#cccccc 1pt solid;padding:1pt;"&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;DELETE &lt;/span&gt;t1&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;FROM &lt;/span&gt;MyTable1 &lt;span style="color:#0000ff;"&gt;AS &lt;/span&gt;t1 &lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;inner join &lt;/span&gt;(&lt;span style="color:#0000ff;"&gt;SELECT &lt;/span&gt;KeyValue1, KeyValue2 &lt;span style="color:#0000ff;"&gt;from &lt;/span&gt;MyTable2) t2 &lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;    ON &lt;/span&gt;t1.KeyValue1 = t2.KeyValue1 &lt;span style="color:#0000ff;"&gt;and &lt;/span&gt;t1.KeyValue2 = t2.KeyValue2&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I simplified the query, because the original query is a lot more complex than this one. Again, it&amp;#39;s not difficult, but could be useful if you run into a similar situation&lt;/p&gt;</description></item><item><title>How to - Create a missing designer.cs file</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/10/17/how-to-create-a-missing-designer-cs-file.aspx</link><pubDate>Fri, 17 Oct 2008 09:49:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:475653</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;I was running into this just now and found a quick way to solve it, so I just posted it for future reference.&lt;/p&gt;
&lt;p&gt;I have an ASP.Net web application project in .Net 2.0 which was migrated from .Net 1.1 some time ago. I noticed that a few aspx pages did not have a designer.cs file. All controls on those pages were listed as protected variable in the main code behind page, like this example:&lt;/p&gt;
&lt;div style="font-size:9pt;background:#f5f5f5;overflow:auto;width:100%;color:black;font-family:Courier New;border:#cccccc 1pt solid;padding:1pt;"&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; An example label&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; System.Web.UI.WebControls.&lt;span style="color:#2b91af;"&gt;Label&lt;/span&gt; Label2;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And it annoyed me. It was not consistent with the new pages in the application, and most other aspx pages that were also there during migration did have the designer.cs file. So how to solve this, in order to get a more consistent use of ASP.Net. I followed the following steps to do this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First step - Make sure the latest version of the project is on your machine.&lt;/li&gt;
&lt;li&gt;Second step is to remove the protected variables for the controls from the normal code behind cs file.&lt;/li&gt;
&lt;li&gt;Now right-Click on the project and select &amp;#39;Convert to Web Application&amp;#39;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The missing designer.cs is now created and added to the project. The protected variables, which were removed from the main code behind class are now in the partial class in the newly created designer.cs. The class in the original code behind class is also changed to a partial class.&lt;/p&gt;
&lt;p&gt;If you forget step 2 and still want to remove the protected variables from your code behind class, then follow the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Remove the protected variables for the controls from the normal code behind cs file.&lt;/li&gt;
&lt;li&gt;Open the ASPX file and make sure you view it in Source (HTML) mode &lt;/li&gt;
&lt;li&gt;Select the entire HTML mark up using CTRL-A&lt;/li&gt;
&lt;li&gt;Now press CTRL-K followed by CTRL-F&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The HTML mark-up will be re-aligned and the designer.cs file will be recreated, including all the protected variables.&lt;/p&gt;</description></item><item><title>How to: Use OleDb to import text files (tab, csv, custom)</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/07/15/how-to-use-OleDb-to-import-comma-or-tab-delimited-files.aspx</link><pubDate>Tue, 15 Jul 2008 11:52:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:466241</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;I have been browsing the web for a good and simple class to handle delimited file imports. My current assignment has an import option that needs to deal with that. However, the current implementation (using StreamReader) is not good enough. It doesn&amp;#39;t handle all the exceptions you encounter with delimited files. I found a number of examples on the internet, but none of them really suited my needs. What I really missed was a simple example that I could extend so that it would suite my needs. So, being the developer that I am, I created my own class to import delimited files. After this was completed, I though I&amp;#39;d share it as an example to others. &lt;/p&gt;
&lt;h2&gt;Using StreamReader&lt;/h2&gt;
&lt;p&gt;The easiest way to process delimited files is to use a StreamReader object. You then simply open the file, read each line and then use the split method to get the various column values. For example: &lt;/p&gt;

&lt;div style="border-right:#cccccc 1pt solid;padding-right:1pt;border-top:#cccccc 1pt solid;padding-left:1pt;font-size:9pt;background:#f5f5f5;padding-bottom:1pt;overflow:auto;border-left:#cccccc 1pt solid;width:100%;color:black;padding-top:1pt;border-bottom:#cccccc 1pt solid;font-family:Courier New;"&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; ImportDelimitedFile(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; filename, &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; delimiter)&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;{&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;StreamReader&lt;/span&gt; file = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;StreamReader&lt;/span&gt;(filename))&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; {&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; line;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;while&lt;/span&gt; ((line = file.ReadLine()) != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;
            if&lt;/span&gt; (line.Trim().Length &amp;gt; 0)&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;[] columns = line.Split(delimiter, &lt;span style="color:#2b91af;"&gt;StringSplitOptions&lt;/span&gt;.None);&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#008000;"&gt;// Add code to process the columns&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;In a lot of cases this works just fine, but there are limitations to this scenario.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It&amp;#39;s difficult to split a line into columns. For example, when you use Comma Separated File (CSV) it is well possible that a comma is in one of the columns. Using a simple string.Split is therefor not an option&lt;/li&gt;
&lt;li&gt;When you only need certain columns or lines, you will need to scan all of them and handle all lines and filter what you need&lt;/li&gt;
&lt;li&gt;It&amp;#39;s not possible to return to a previous line&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Using the Jet Engine&lt;/h2&gt;
&lt;p&gt;The above mentioned problems are eliminated when you use the Jet engine. The following code shows how a CSV file can be processed.&lt;/p&gt;

&lt;div style="border-right:#cccccc 1pt solid;padding-right:1pt;border-top:#cccccc 1pt solid;padding-left:1pt;font-size:9pt;background:#f5f5f5;padding-bottom:1pt;overflow:auto;border-left:#cccccc 1pt solid;width:100%;color:black;padding-top:1pt;border-bottom:#cccccc 1pt solid;font-family:Courier New;"&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; ImportCsvFile(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; filename)&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;{&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color:#2b91af;"&gt;FileInfo&lt;/span&gt; file = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;FileInfo&lt;/span&gt;(filename);&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;OleDbConnection&lt;/span&gt; con = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OleDbConnection&lt;/span&gt;(&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;Provider=Microsoft.Jet.OLEDB.4.0;Data
            Source=\&amp;quot;&amp;quot;&lt;/span&gt; + file.DirectoryName + &lt;span style="color:#a31515;"&gt;&amp;quot;\&amp;quot;;Extended Properties=&amp;#39;text;HDR=Yes;FMT=Delimited(,)&amp;#39;;&amp;quot;&lt;/span&gt;))&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; {&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;OleDbCommand&lt;/span&gt; cmd = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OleDbCommand&lt;/span&gt;(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515;"&gt;&amp;quot;SELECT * FROM [{0}]&amp;quot;&lt;/span&gt;, file.Name), con))&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; con.Open();&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#008000;"&gt;
            // Using a DataReader to process the data&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;
            using&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;OleDbDataReader&lt;/span&gt; reader = cmd.ExecuteReader())&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;while&lt;/span&gt; (reader.Read())&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#008000;"&gt;// Process the current reader entry...&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#008000;"&gt;
            // Using a DataTable to process the data&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;
            using&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;OleDbDataAdapter&lt;/span&gt; adp = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OleDbDataAdapter&lt;/span&gt;(cmd))&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#2b91af;"&gt;DataTable&lt;/span&gt; tbl = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DataTable&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;MyTable&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; adp.Fill(tbl);&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;DataRow&lt;/span&gt; row &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; tbl.Rows)&lt;/pre&gt;
&lt;pre style="margin:0px;"&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#008000;"&gt;// Process the current row...&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;As you can see in the example, once you have the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms254953.aspx"&gt;Command object&lt;/a&gt;, you have the option of using anything a command object will allow you to do. You could process the file using a &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms254509.aspx"&gt;DataReader&lt;/a&gt; object, create a &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx"&gt;DataTable&lt;/a&gt; object containing the data or even add a where clause to the CommandText of your Command object to specifiy better which data is to be imported.&lt;/p&gt;
&lt;h2&gt;Helper Class&lt;br /&gt;&lt;/h2&gt;
&lt;p&gt;Using this, and the information provided in this &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms974559.aspx"&gt;Microsoft Article&lt;/a&gt;, I created a small class that allows you to import delimited files. The class is very basic, but can easily be extended to suit your specific needs. This class will solve the most important issues when you&amp;#39;re going to use Jet as your import engine.&lt;/p&gt;
&lt;p&gt;Some things you need to consider when you are importing delimited files, be it with this class or using custom code:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Jet engine makes assumptions about the content of the file. This can result in incorrect imports. For example, it might think a column contains date values. But in fact, you&amp;#39;re file should treat the columns as a string. In these cases, you should create a Schema.Ini file that describes the type of value for each column. The class creates a Schema.Ini file before it opens the delimited file, but only to specify what the delimiter is. You may want to change this to use pre-defined ini files that describe your input file. Details on the Schema.Ini file can be found &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms709353(VS.85).aspx"&gt;here&lt;/a&gt; .&lt;/li&gt;
&lt;li&gt;The class uses an &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.aspx"&gt;OleDbDataReader&lt;/a&gt; to read each line in the import file. But it is easily replaced with the option of adding the data into a DataSet or DataTable object. It&amp;#39;s also possible to use &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx"&gt;SqlBulkCopy&lt;/a&gt; to instantly insert all the data into a SQL server database.&lt;/li&gt;
&lt;li&gt;The above mentioned &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms974559.aspx"&gt;Microsoft Article&lt;/a&gt; is the best starting point for this type of import. You might want to read that before you start building imports for delimited files, even if this class is usefull to you. The article provides interesting background information and links to various Microsoft resources with more details and information.&lt;/li&gt;
&lt;li&gt;The helper class uses an event to allow you to handle the information being read. You can, of course, also provide an overridable method.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Valuable resources&lt;/h2&gt;
&lt;p&gt;The information I used to to build this class was found on the Internet. I used the following resources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms974559.aspx"&gt;Much ADO About Text Files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://www.codeproject.com/KB/database/ReadTextFile.aspx"&gt;Read text file (txt, csv, log, tab, fixed length)&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;The code presented in the helper class is not an all-purpose import solution. It&amp;#39;s just a basic class to help you build your own import class. If you need other import types, or a way to influence the content of the default Schema.ini file, you will need to do that your self. If you find any problems, please feel free to point them out to me.&lt;/p&gt;
&lt;p&gt;You can download the file &lt;a href="http://bloggingabout.net/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.46.62.41/ImportUsingJet.zip" title="Click here to download the code"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This article is also &lt;a target="_blank" href="http://www.codeproject.com/KB/cs/UsingJetForImport.aspx" title="See article on CodeProject"&gt;published on CodeProject.com&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Keep track of data changes using a SQL trigger</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/02/08/keep-track-of-data-changes-using-a-sql-trigger.aspx</link><pubDate>Fri, 08 Feb 2008 09:26:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:457870</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;In my current project, we calculate the status of tasks that a user needs to do and store the status in a table. This happens on a daily basis.&amp;nbsp;Once every week, we calculate which items are overdue and inform the user by email to take appropriate action. However, sometimes our users complain that they receive such an email and that there aren&amp;#39;t any tasks that require immediate action.&lt;/p&gt;
&lt;p&gt;We know that this happens, but since we calculate the status once per day and when the user logs on to the application, we cannot really see why this happens. What we needed was a way to see when a tasks moves to another state. We decided to create a history table which contains the information in our status table and update that history table using a trigger. But the examples we found in Books on Line and other resources on the web just didn&amp;#39;t give us the information we needed. &lt;/p&gt;
&lt;p&gt;So I called my good friend &lt;a class="" href="http://bloggingabout.net/blogs/wellink/default.aspx" target="_blank"&gt;Patrick Wellink&lt;/a&gt; who I know to be a SQL guru. He had written a generic trigger which can be used to audit changes and &lt;a class="" href="http://www.sqlservercentral.com/scripts/Miscellaneous/31241/" target="_blank"&gt;posted this on SqlServerCentral.Com&lt;/a&gt;. The script looks like this:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;CREATE TRIGGER &lt;/span&gt;TRG_##YOUR_TABLE##&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;ON &lt;/span&gt;[DBO].[##YOUR_TABLE##]&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;FOR DELETE&lt;/span&gt;,&lt;span style="COLOR:blue;"&gt;INSERT&lt;/span&gt;,&lt;span style="COLOR:blue;"&gt;UPDATE&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:green;"&gt;-- JUST CHANGE ##YOUR_TABLE## INTO YOUR OWN TABLENAME TO MAKE IT WORK &lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@ACT &lt;span style="COLOR:blue;"&gt;CHAR&lt;/span&gt;(6)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@DEL &lt;span style="COLOR:blue;"&gt;BIT&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@INS &lt;span style="COLOR:blue;"&gt;BIT &lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@SQLSTRING &lt;span style="COLOR:blue;"&gt;VARCHAR&lt;/span&gt;(2000)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@DEL = 0&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@INS = 0&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF EXISTS &lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;SELECT TOP &lt;/span&gt;1 1 &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;DELETED) &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@DEL=1&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF EXISTS &lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;SELECT TOP &lt;/span&gt;1 1 &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;INSERTED) &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@INS = 1 &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@INS = 1 &lt;span style="COLOR:blue;"&gt;AND &lt;/span&gt;@DEL = 1 &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@ACT = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;UPDATE&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@INS = 1 &lt;span style="COLOR:blue;"&gt;AND &lt;/span&gt;@DEL = 0 &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@ACT = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;INSERT&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@DEL = 1 &lt;span style="COLOR:blue;"&gt;AND &lt;/span&gt;@INS = 0 &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@ACT = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;DELETE&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@INS = 0 &lt;span style="COLOR:blue;"&gt;AND &lt;/span&gt;@DEL = 0 &lt;span style="COLOR:blue;"&gt;RETURN&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF NOT EXISTS &lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;SELECT &lt;/span&gt;* &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;SYSOBJECTS &lt;span style="COLOR:blue;"&gt;WHERE &lt;/span&gt;ID = &lt;span style="COLOR:blue;"&gt;OBJECT_ID&lt;/span&gt;(N&lt;span style="COLOR:#a31515;"&gt;&amp;#39;[DBO].[AUDIT_##YOUR_TABLE##]&amp;#39;&lt;/span&gt;) &lt;span style="COLOR:blue;"&gt;AND OBJECTPROPERTY&lt;/span&gt;(ID, N&lt;span style="COLOR:#a31515;"&gt;&amp;#39;ISUSERTABLE&amp;#39;&lt;/span&gt;) = 1)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- CREATE A MEMORY TABLE CONTAINING THE FIELDS AND TYPES OF THE TABLE&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@MEMTABLE &lt;span style="COLOR:blue;"&gt;TABLE&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ( &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ID &lt;span style="COLOR:blue;"&gt;INT IDENTITY&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ,COLUMNAME &lt;span style="COLOR:blue;"&gt;SYSNAME&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ,TYPENAME &lt;span style="COLOR:blue;"&gt;VARCHAR&lt;/span&gt;(20)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  )&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- INSERT THE COLUMNAMES AND THE DATATYPES&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;INSERT &lt;/span&gt;@MEMTABLE &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (COLUMNAME,TYPENAME) &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SELECT NAME&lt;/span&gt;,TYPE_NAME(XTYPE) &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;SYSCOLUMNS &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;WHERE &lt;/span&gt;ID = &lt;span style="COLOR:blue;"&gt;OBJECT_ID&lt;/span&gt;(&lt;span style="COLOR:#a31515;"&gt;&amp;#39;[DBO].[##YOUR_TABLE##]&amp;#39;&lt;/span&gt;) &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;ORDER BY &lt;/span&gt;COLID&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@CUR &lt;span style="COLOR:blue;"&gt;INTEGER&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@MAX &lt;span style="COLOR:blue;"&gt;INTEGER&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@SQLSTR &lt;span style="COLOR:blue;"&gt;AS VARCHAR&lt;/span&gt;(8000)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@CURCOL &lt;span style="COLOR:blue;"&gt;SYSNAME&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;DECLARE &lt;/span&gt;@COLTYPE &lt;span style="COLOR:blue;"&gt;AS VARCHAR&lt;/span&gt;(10)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- SETUP VARIABLES&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@SQLSTR = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@CUR=1&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SELECT &lt;/span&gt;@MAX = &lt;span style="COLOR:blue;"&gt;MAX&lt;/span&gt;(ID) &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;@MEMTABLE&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- LOOP EVEY FIELD&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;WHILE &lt;/span&gt;@CUR &amp;lt;= @MAX&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- GET VALUES FROM THE MEMTABLE&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SELECT &lt;/span&gt;@CURCOL = COLUMNAME,@COLTYPE = TYPENAME &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;@MEMTABLE &lt;span style="COLOR:blue;"&gt;WHERE &lt;/span&gt;ID = @CUR&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@COLTYPE = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;INT&amp;#39; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;OR &lt;/span&gt;@COLTYPE = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;BIGINT&amp;#39; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;OR &lt;/span&gt;@COLTYPE=&lt;span style="COLOR:#a31515;"&gt;&amp;#39;UNIQUEIDENTIFIER&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- WE DO WANT TO COPY INT/BIGINT/UNIQUEIDENTIFIER FIELDS BUT IF THEY ARE AN &lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- IDENTITY OR A ROWGUIDCOLUMN WE DO NOT WANT TO COPY THAT ATTRIBUTES &lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@SQLSTR = @SQLSTR + &lt;span style="COLOR:#a31515;"&gt;&amp;#39; CAST(&amp;#39;&lt;/span&gt;+@CURCOL + &lt;span style="COLOR:#a31515;"&gt;&amp;#39; AS &amp;#39;&lt;/span&gt;+@COLTYPE+&lt;span style="COLOR:#a31515;"&gt;&amp;#39;) AS [&amp;#39; &lt;/span&gt;+ @CURCOL +&lt;span style="COLOR:#a31515;"&gt;&amp;#39;] &amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;ELSE&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- ANOTHER FIELD DO NOTHING JUST COPY IT AS IT IS&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@SQLSTR = @SQLSTR + &lt;span style="COLOR:#a31515;"&gt;&amp;#39; &amp;#39;&lt;/span&gt;+@CURCOL + &lt;span style="COLOR:#a31515;"&gt;&amp;#39; AS [&amp;#39; &lt;/span&gt;+ @CURCOL +&lt;span style="COLOR:#a31515;"&gt;&amp;#39;] &amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@CUR &amp;lt;= @MAX - 1 &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@SQLSTR=@SQLSTR + &lt;span style="COLOR:#a31515;"&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@CUR = @CUR + 1&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;END&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- ADD THE AUDIT FIELDS&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@SQLSTR = @SQLSTR +&lt;span style="COLOR:#a31515;"&gt;&amp;#39;,CAST(&amp;#39;&amp;#39; &lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;span style="COLOR:#a31515;"&gt;&amp;#39;&amp;#39; AS CHAR(6)) AS TRG_ACTION,CAST(GETDATE() AS DATETIME) AS TRG_DATE&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- SET UP THE SELECT FOR CREATING THE AUDIT TABLE&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET &lt;/span&gt;@SQLSTR = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;SELECT TOP 0 &amp;#39; &lt;/span&gt;+ @SQLSTR + &lt;span style="COLOR:#a31515;"&gt;&amp;#39; INTO [DBO].[AUDIT_##YOUR_TABLE##] FROM [DBO].[##YOUR_TABLE##]&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;EXEC&lt;/span&gt;(@SQLSTR)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;END&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@ACT = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;INSERT&amp;#39; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;INSERT &lt;/span&gt;[DBO].[AUDIT_##YOUR_TABLE##] &lt;span style="COLOR:blue;"&gt;SELECT &lt;/span&gt;*,&lt;span style="COLOR:#a31515;"&gt;&amp;#39;INSERT&amp;#39; &lt;/span&gt;,&lt;span style="COLOR:blue;"&gt;GETDATE&lt;/span&gt;() &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;INSERTED&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@ACT = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;DELETE&amp;#39; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;INSERT &lt;/span&gt;[DBO].[AUDIT_##YOUR_TABLE##] &lt;span style="COLOR:blue;"&gt;SELECT &lt;/span&gt;*,&lt;span style="COLOR:#a31515;"&gt;&amp;#39;DELETE&amp;#39; &lt;/span&gt;,&lt;span style="COLOR:blue;"&gt;GETDATE&lt;/span&gt;() &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;DELETED&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;@ACT = &lt;span style="COLOR:#a31515;"&gt;&amp;#39;UPDATE&amp;#39; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;INSERT &lt;/span&gt;[DBO].[AUDIT_##YOUR_TABLE##] &lt;span style="COLOR:blue;"&gt;SELECT &lt;/span&gt;*,&lt;span style="COLOR:#a31515;"&gt;&amp;#39;UPDATE&amp;#39; &lt;/span&gt;,&lt;span style="COLOR:blue;"&gt;GETDATE&lt;/span&gt;() &lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;INSERTED&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It does almost everything we needed. It copies the information to a new table when something happens to the row in the original table. Thanks Patrick for helping us with this script.&lt;/p&gt;
&lt;p&gt;We modified the code for the update section, because we only wanted to store the old information in the AUDIT table when certain fields are modified:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;INSERT &lt;/span&gt;[DBO].[AUDIT_##YOUR_TABLE##] &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;SELECT &lt;/span&gt;DELETED.*,&lt;span style="COLOR:blue;"&gt;GETDATE&lt;/span&gt;()&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;FROM &lt;/span&gt;INSERTED&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;INNER JOIN &lt;/span&gt;DELETED &lt;span style="COLOR:blue;"&gt;ON &lt;/span&gt;DELETED.StatusID = INSERTED.StatusID &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;WHERE &lt;/span&gt;(INSERTED.Status &amp;lt;&amp;gt; DELETED.STATUS) &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;OR &lt;/span&gt;(INSERTED.CountAlerts &amp;lt;&amp;gt; DELETED.CountAlerts) &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;OR &lt;/span&gt;(INSERTED.AlertViewed &amp;lt;&amp;gt; DELETED.AlertViewed)&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This way, we get the information as it was before the update and only when the fields that we want to monitor are changed. Works great!&lt;/p&gt;</description></item><item><title>How to: Quickly check if data exists in your SQL table</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/12/21/how-to-quickly-check-if-data-exists-in-your-sql-table.aspx</link><pubDate>Fri, 21 Dec 2007 07:22:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:447660</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;I was confronted with a slow performing stored procedure in SQL server this week. The procedure was to retrieve one row from a table. But before that row could be retrieved, an update procedure was called to make sure&amp;nbsp;all rows&amp;nbsp;in that table had the correct status. That update procedure first checked the number of rows in a table to see if there were rows to be be updated. It used a piece of SQL similar to this:&amp;nbsp;&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;CREATE PROCEDURE &lt;/span&gt;dbo.spMyProcedure&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET NOCOUNT ON&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;IF &lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;SELECT count&lt;/span&gt;(UserID) &lt;span style="COLOR:blue;"&gt;from &lt;/span&gt;UserTable) &amp;gt; 0&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;-- Process the items in the table&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;END&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;GO&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will obviously work. But on a table that contains more than 150,000 rows this can take some time. But why count the number of rows if all we need to know if there is at least one row present. I changed the IF statement a little and gave the procedure a new name so that I could compare both:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;CREATE PROCEDURE &lt;/span&gt;dbo.spMyProcedureNew&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;SET NOCOUNT ON&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;   IF EXISTS&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;SELECT top &lt;/span&gt;1 UserID &lt;span style="COLOR:blue;"&gt;from &lt;/span&gt;UserTable)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;   BEGIN&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;    &lt;span style="COLOR:green;"&gt;-- Process the items in the view&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;   END&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;GO&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I then called both with the Execution plan on and found this result:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bloggingabout.net/blogs/jschreuder/WindowsLiveWriter/WindowsLiveWriterBeta2_13B0F/plan.jpg"&gt;&lt;img src="http://bloggingabout.net/blogs/jschreuder/WindowsLiveWriter/WindowsLiveWriterBeta2_13B0F/plan.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A logical conclusion, just checking if there is one row in the table is much faster than checking of the number of records is more than zero.&amp;nbsp;When you compare the subtree cost of the old procedure (0.726) with the subtree cost of the new procedure (0.00641), you can see a performance gain of a factor 113&amp;nbsp;.&amp;nbsp;But how does SqlProfiler look at both queries? Well, here&amp;#39;s that result:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bloggingabout.net/blogs/jschreuder/WindowsLiveWriter/WindowsLiveWriterBeta2_13B0F/prof.jpg"&gt;&lt;img src="http://bloggingabout.net/blogs/jschreuder/WindowsLiveWriter/WindowsLiveWriterBeta2_13B0F/prof.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the duration of the old procedure averages at 34.4 and the new procedure averages at 12.2. The new proceduer is still a factor 2.8 faster than the old procedure. But you&amp;#39;ll also need to look at the difference in CPU time (0 for the new procedure and 31 for the old procedure) and the number of reads (19 for the new compared to 709 for the old procedure) to conclude that checking for at least one row is a lot more efficient than counting the number of rows.&lt;/p&gt;</description></item><item><title>How to: Check if the specified URL really exists</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/12/12/how-to-check-if-the-specified-url-really-exists.aspx</link><pubDate>Wed, 12 Dec 2007 09:18:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:445412</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;I think a lot of people need to do this, and we do in our project. We created a method that will check if URLs specified in our database (a couple of hundred) actually exist. Our support team uses the result of that check to update incorrect URLs in our application. I extracted the method and removed some project specific stuff to show it here:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:gray;"&gt;///&lt;/span&gt;&lt;span style="COLOR:green;"&gt; &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:gray;"&gt;///&lt;/span&gt;&lt;span style="COLOR:green;"&gt; Checks the status of the specified URL.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:gray;"&gt;///&lt;/span&gt;&lt;span style="COLOR:green;"&gt; &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:gray;"&gt;///&lt;/span&gt;&lt;span style="COLOR:green;"&gt; &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;param name=&amp;quot;url&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;The URL that needs to be checked&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:gray;"&gt;///&lt;/span&gt;&lt;span style="COLOR:green;"&gt; &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;param name=&amp;quot;statusText&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;The status text associated with the specified URL&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:gray;"&gt;///&lt;/span&gt;&lt;span style="COLOR:green;"&gt; &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;An Integer value which is the result of the check action&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; CheckUrl(&lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; url, &lt;span style="COLOR:blue;"&gt;out&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; statusText)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; status = -1;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; statusText = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Unknown status&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;ServerXMLHTTP30Class&lt;/span&gt; http = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;ServerXMLHTTP30Class&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; http.setTimeouts(5000, 5000, 5000, 5000);&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; http.open(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;HEAD&amp;quot;&lt;/span&gt;, url, &lt;span style="COLOR:#2b91af;"&gt;Missing&lt;/span&gt;.Value, &lt;span style="COLOR:#2b91af;"&gt;Missing&lt;/span&gt;.Value, &lt;span style="COLOR:#2b91af;"&gt;Missing&lt;/span&gt;.Value);&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; http.send(&lt;span style="COLOR:#2b91af;"&gt;Missing&lt;/span&gt;.Value);&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; status = http.status;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;// Status 200 specifies the http.send was successful&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (status != 200)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; statusText = http.statusText;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; statusText = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;OK&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;catch&lt;/span&gt; (&lt;span style="COLOR:#2b91af;"&gt;COMException&lt;/span&gt; com)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; statusText = com.Message;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; status;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For most URLs, this method works fine for us. There are some cases where the method fails. For example, some urls (for intranet sites)&amp;nbsp;require a user with sufficient access rights to be logged on. One problem kind of worries us. The http.Send method sometimes throws the following exception:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;System.Runtime.InteropServices.COMException (0x80072EE2): &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;   Exception from HRESULT: 0x80072EE2&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp; at MSXML2.ServerXMLHTTP30Class.send(Object varBody)&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I&amp;#39;m wondering if someone out there can tell me why, or maybe someone knows of a better (and faster) way to check if a URL exists.&lt;/p&gt;</description></item><item><title>Crystal Reports for Visual Studio 2005 deployment trouble</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/12/10/crystal-reports-for-visual-studio-2005-deployment-trouble.aspx</link><pubDate>Mon, 10 Dec 2007 12:53:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:444639</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;I just spent 4 hours of figuring out why the reports we developed using Crystal Reports would not show the graphs after being deployed to our production server. We checked everything from access rights to proper installation of Crystal reports on the server. Below are a few things you may want to check when you need to deploy a .Net 2.0 web application that integrates Crystal Reports:&lt;/p&gt;
&lt;p&gt;
&lt;h3&gt;Deploy Crystal components&lt;/h3&gt;
&lt;p&gt;First, and rather obvious, is to make sure the correct version of Crystal components are installed on the server. If you have the Visual Studio SDK installed, you can look for CRRedist2005_x86.msi, which is in this folder C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\CrystalReports on your machine. Running that installation on the server will make sure all components required for Crystal Reports are properly installed on your machine.&lt;/p&gt;
&lt;p&gt;If you have a setup project for your web application, you can add a merge module to that project. Crystal Reports provides four merge modules for download at &lt;a class="" href="http://support.businessobjects.com/downloads/runtime.asp#07" target="_blank"&gt;this location&lt;/a&gt;. Depending on your needs, you may need to add any combination of these to your setup project. Which module is required for your application can be found in &lt;a class="" title="Right-Click to download" href="http://diamond.businessobjects.com/system/files/deployingcrystalceports10for.net.doc" target="_blank"&gt;this document&lt;/a&gt; on the Business Objects support site.&lt;/p&gt;
&lt;p&gt;
&lt;h3&gt;Web.Config settings&lt;/h3&gt;
&lt;p&gt;In order for a Crystal Reports viewer to work, the following settings must be added to the appSettings section in the web.Config file:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;add&lt;/span&gt;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;key&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;CrystalImageCleaner-AutoStart&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;value&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;true&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;add&lt;/span&gt;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;key&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;CrystalImageCleaner-Sleep&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;value&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;60000&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;add&lt;/span&gt;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;key&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;CrystalImageCleaner-Age&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;value&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;120000&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will ensure that the temporary images for Crystal are removed when they are no longer required. The following setting must be added the the httpHandlers section.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;add&lt;/span&gt;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;verb&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;GET&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;path&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;CrystalImageHandler.aspx&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;type&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;CrystalDecisions.Web.CrystalImageHandler, &lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;    CrystalDecisions.Web, &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is required, because otherwise all you will see is an empty box with a red cross in it.&lt;/p&gt;
&lt;h3&gt;aspnet_client files&lt;/h3&gt;
&lt;p&gt;Last, but certainly not least, check the aspnet_client folder in the root folder of your web site. This folder should contain a folder with the name CrystalReportWebFormViewer3. That folder must exist in the following path: system_web\2_0_50727. If that folder is not there, copy it from your local machine. It should be in the folder C:\WINNT\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles.&lt;/p&gt;</description></item><item><title>.Net Zip library</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/31/net-zip-library.aspx</link><pubDate>Wed, 31 Oct 2007 11:17:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:415015</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;The MSDN blogs are a really great source for all sorts of information. I browse &lt;a class="" href="http://blogs.msdn.com/" target="_blank"&gt;the main blog page&lt;/a&gt; regularly, just to get a feeling of what is happening on the Microsoft side of things. This morning I found a link to a Codeplex project which encapsulates the &lt;a class="" href="http://msdn2.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx" target="_blank"&gt;System.IO.Compression.DeflateStream&lt;/a&gt; class to allow you to read and write zip files. &lt;/p&gt;
&lt;p&gt;The project can be found here:&amp;nbsp;&lt;a href="http://www.codeplex.com/DotNetZip"&gt;http://www.codeplex.com/DotNetZip&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Another &amp;quot;What the F**K&amp;quot; moment</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/02/another-quot-what-the-f-k-quot-moment.aspx</link><pubDate>Tue, 02 Oct 2007 09:40:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:382658</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;I tried compiling my application just now and got this error message from the compiler:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;Preparing resources...&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;Updating references...&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;Performing main compilation...&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;error CS0583: Internal Compiler Error (0xc0000005 at address 77FCD43E): likely culprit is &amp;#39;PARSE&amp;#39;.&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;An internal error has occurred in the compiler. To work around this problem, try simplifying or &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;changing the program near the locations listed below. Locations at the top of the list are closer &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;to the point at which the internal error occurred.&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;c:\inetpub\wwwroot\Intra\Hierarchy.aspx.cs: error CS0586: Internal Compiler Error: stage &amp;#39;PARSE&amp;#39;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;error CS0587: Internal Compiler Error: stage &amp;#39;PARSE&amp;#39;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;error CS0587: Internal Compiler Error: stage &amp;#39;BEGIN&amp;#39;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Excuse me?!?!?! The last time I ever received errors like this was in 1996, while building applications for good-old MS-Dos. The Microsoft C compiler in some cases could not parse the code and presented you with a &amp;quot;Too complex&amp;quot; error. The only way around this was to re-order the code. But in the .Net age I never came across this error. Until now that is.&lt;/p&gt;
&lt;p&gt;And what&amp;#39;s even stranger is that a rebuild of the app solved the problem. I&amp;#39;m lost. Any one out there has any experience with this error?&lt;/p&gt;</description></item><item><title>What the F**K is the 'Grady' operator</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/01/what-the-f-k-is-the-grady-operator.aspx</link><pubDate>Mon, 01 Oct 2007 13:31:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:382015</guid><dc:creator>Jan Schreuder</dc:creator><description>&lt;p&gt;The web application I&amp;#39;m working on logs errors in a log file using Log4Net. Nothing new, loads of applications do that. But I was surprised when I found the following error message:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;System.Data.SyntaxErrorException: Syntax error: Missing operand after &amp;#39;grady&amp;#39; operator.&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now what in heavens name is a &amp;#39;Grady&amp;#39; operator. I had no clue. Google only knows Grady from the book &amp;quot;&lt;em&gt;&lt;a class="" title="http://www.amazon.com/Object-Oriented-Analysis-Design-Applications-3rd/dp/020189551X/ref=pd_bbs_sr_1/002-7242484-6456822?ie=UTF8&amp;amp;s=books&amp;amp;qid=1191245720&amp;amp;sr=8-1" target="_blank"&gt;Object-Oriented Analysis And Design With Applications&lt;/a&gt;&lt;/em&gt;&amp;quot; and other OO related work. So no solution to be found there. So what could it be?&lt;/p&gt;
&lt;p&gt;I looked into the log file again and checked if the exception was raised more than once. I found more interesting &amp;#39;operators&amp;#39;: &amp;#39;Toole&amp;#39;, &amp;#39;Amore&amp;#39;,&amp;#39;Sullivan&amp;#39;. Wait a minute there all names. I checked the stack traces for these exceptions and then it dawned on me. The error was raised when the user clicked a filter button. The web page where the error was raised showed a user list. Apparently, the user was looking for someone named O&amp;#39;Toole or O&amp;#39;Sullivan. I checked the code and found this:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (txtUserFilter.Text != String.Empty)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataTable.DefaultView.RowFilter = &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;.Format(&amp;quot;NAME like &amp;#39;%{0}%&amp;#39;&amp;quot;, txtUserFilter.Text);&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will work fine of course, provided the text string does not contain any single quotes. The following solved my problem:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;if&lt;/span&gt;(txtUserFilter.Text != String.Empty)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataTable.DefaultView.RowFilter = &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;.Format(&amp;quot;NAME like &amp;#39;%{0}%&amp;#39;&amp;quot;, txtUserFilter.Text.Replace(&amp;quot;&amp;#39;&amp;quot;, &amp;quot;&amp;#39;&amp;#39;&amp;quot;));&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;}&lt;/pre&gt;&lt;/div&gt;</description></item></channel></rss>