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

<channel>
	<title>Pushing Pixels &#187; programming</title>
	<atom:link href="http://familywhitfield.co.uk/wordpress/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://familywhitfield.co.uk/wordpress</link>
	<description>Computing and Digital Imaging</description>
	<lastBuildDate>Thu, 24 Mar 2011 20:54:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Thoughts on a &#8216;Powerful&#8217; API</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 16:02:41 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=17</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/' addthis:title='Thoughts on a &#8216;Powerful&#8217; API' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>One of the words that keeps coming up when I have conversations about new products is that the API must be &#8220;powerful&#8221;. While intuitively this sounds good &#8211; after all, who wants to develop an API that is a bit wimpy &#8211; how can you measure and judge the power of one API over another? [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/' addthis:title='Thoughts on a &#8216;Powerful&#8217; API' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>One of the words that keeps coming up when I have conversations about new products is that the API must be &#8220;powerful&#8221;. While intuitively this sounds good &#8211; after all, who wants to develop an API that is a bit wimpy &#8211; how can you measure and judge the power of one API over another? I&#8217;m pretty sure that you can&#8217;t assign a wattage to a function call.<br />
<span id="more-17"></span></p>
<p>Say we have a scene graph that lets a caller insert objects into a hierarchy. An object can reference other objects using  a standard instancing metaphor. Lets say this manifests itself like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Add child node to parent</span>
<span style="color: #0000ff;">int</span> SceneGraph<span style="color: #008080;">::</span><span style="color: #007788;">AddObject</span> <span style="color: #008000;">&#40;</span>Node <span style="color: #000040;">*</span>parent, <span style="color: #0000ff;">const</span> Node <span style="color: #000040;">*</span>child<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Such an API makes it easy to put in a circular dependency, which would cause subsequent scene graph traversals to loop ad-infinitum. So it would be trivial here to make the method check that parent and child are not the same. But what if parent is indirectly reference by child? E.g.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">start with A <span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span> B <span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span> C
call SceneGraph<span style="color: #008080;">::</span><span style="color: #007788;">AddObject</span> <span style="color: #008000;">&#40;</span>C, A<span style="color: #008000;">&#41;</span></pre></div></div>

<p>So, if AddObject were to be &#8220;powerful&#8221;, would it check for this and return an error? It would certainly make the method robust, as you could not poke invalid data at it. But does robust==powerful?</p>
<p>I would say no. Because even though it stops a user doing something daft that could be hard to diagnose, it does not scale. If the code has to traverse the graph every time a new node is added to the scene graph, then the act of building a model with hundreds or thousands of objects will execute in O(n^2) time complexity. By making this API robust, you actually reduce its power by imposing an overhead upon the user.</p>
<p>Most scene building code will be well behaved &#8211; there will be enough knowledge at the application end to &#8220;know&#8221; that the data is good. And for those times when the application does not know, we can supply a method like:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Check if one object is a child of another</span>
<span style="color: #0000ff;">bool</span> SceneGraph<span style="color: #008080;">::</span><span style="color: #007788;">IsChild</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> Node <span style="color: #000040;">*</span>n0, <span style="color: #0000ff;">const</span> Node <span style="color: #000040;">*</span>n1<span style="color: #008000;">&#41;</span></pre></div></div>

<p>Application code can then query only when needed. The &#8220;power&#8221; here is in enabling the user to make the decision on balancing cost against convenience.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips for returning IDENTITY values from INSERT</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/#comments</comments>
		<pubDate>Sun, 14 Jan 2007 17:04:00 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP2]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=16</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/' addthis:title='Tips for returning IDENTITY values from INSERT' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>There&#8217;s a good article by Scott Guthrie here that describes the basics. Just scroll down to Tutorial 5 for the INSERT specific bit &#8211; it is pretty straightforward and there is no point my repeating it here. One point to note, however, and why I wrote this particular post. The key step in getting this [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/' addthis:title='Tips for returning IDENTITY values from INSERT' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>There&#8217;s a good article by Scott Guthrie <a href="http://aspalliance.com/914_Building_a_DAL_using_Strongly_Typed_TableAdapters_and_DataTables_in_VS_2005_and_ASPNET_20">here</a> that describes the basics. Just scroll down to Tutorial 5 for the INSERT specific bit &#8211; it is pretty straightforward and there is no point my repeating it here.</p>
<p>One point to note, however, and why I wrote this particular post. The key step in getting this working is changing the query type from NonQuery to Scalar. But this can get reset by Visual Studio if you choose the Configure option on the ObjectDataSource&#8217;s smart tags to modify the query in any way. If you don&#8217;t notice this, then suddenly the identity value stops getting returned and your code breaks.</p>
<p>The second tip is that by default the type returned by the insert query is decimal. This can cause some extra casting in your code if you were expecting it to be int. To fix this, just modify the SQL in Scott&#8217;s original article to be this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">CAST</span> <span style="color: #66cc66;">&#40;</span>SCOPE_IDENTITY<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining row counts for all tables in a database</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/#comments</comments>
		<pubDate>Thu, 11 Jan 2007 22:02:33 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP2]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[test driven development]]></category>
		<category><![CDATA[unit-testing]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=13</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/' addthis:title='Determining row counts for all tables in a database' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>Here is a usful snippet if you want a way to get the number of rows in each table in your database. I use this in an admin-only page of the web application to provide some at-a-glance statistics. It is also really useful in unit tests for checking the correctness of business logic that may [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/' addthis:title='Determining row counts for all tables in a database' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>Here is a usful snippet if you want a way to get the number of rows in each table in your database. I use this in an admin-only page of the web application to provide some at-a-glance statistics. It is also really useful in unit tests for checking the correctness of business logic that may create new entries in several tables in one transaction.</p>
<p><span id="more-13"></span></p>
<h3>SQL snippet</h3>
<p>The bit of SQL is quite straightforward, once you delve down into the depths of SQLServer&#8217;s system tables:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
   so<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> TableName<span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>si<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">ROWS</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>RowCount<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
   sys<span style="color: #66cc66;">.</span>sysobjects <span style="color: #993333; font-weight: bold;">AS</span> so
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span>
   sys<span style="color: #66cc66;">.</span>sysindexes <span style="color: #993333; font-weight: bold;">AS</span> si
   <span style="color: #993333; font-weight: bold;">ON</span> OBJECT_ID<span style="color: #66cc66;">&#40;</span>so<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> si<span style="color: #66cc66;">.</span>id
<span style="color: #993333; font-weight: bold;">WHERE</span>
   <span style="color: #66cc66;">&#40;</span>so<span style="color: #66cc66;">.</span>xtype <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'U'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> so<span style="color: #66cc66;">.</span>name
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> TableName</pre></div></div>

<h2>Presenting in a page</h2>
<p>There are a number of ways of getting this into an ASP2 page. I chose to do this via a new table adaptor, and to wrap the query in an Administration class in the business logic layer.</p>
<p>Paste the SQL snippet from above into the query builder to create a new table adapter on the data designer &#8211; I have a separate &#8220;admin.xsd&#8221; to keep these non-user level types away from the core application data types. By default you will get an  adapter called &#8220;sysobjectsTableAdapter&#8221; as it picks its name up from the first table in the query. You can change this if you need to.</p>
<p>You can now go direct to an ASP page by pointing an ObjectDataSource directly at this table adapter, or you can wrap it in an intermediate layer.</p>
<h2>Unit test example</h2>
<p>My unit test framework has a database reset mechanism that empties all tables and then creates a small set of known test data using the business logic layer (BLL). This empty and reset is done in the test fixture setup, and the subsequent raft of tests use a variety of methods to valid the integrity of the data.</p>
<p>A key test is ensuring that the expected number of rows in various tables have been created. This is particularly important as there are a number of linking and cross reference tables that are not directly seen by a user, but are there for the efficiency of the schema. So checking  all these have been set correctly after the BLL has done its work is vital.</p>
<p>In the test class I have something like this :</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>TestFixture<span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> DBReset
<span style="color: #008000;">&#123;</span> <span style="color: #008000;">....</span>
   <span style="color: #0600FF; font-weight: bold;">private</span> Dictionary TableRowCounts  <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary <span style="color: #008000;">;</span>
   <span style="color: #008000;">...</span>
    <span style="color: #008000;">&#91;</span>TestFixtureSetup<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> FixtureSetup<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        TableRowCounts<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span> <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Addresses&quot;</span>, <span style="color: #FF0000;">6</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        TableRowCounts<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span> <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Agencies&quot;</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">...</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This sets up a list of all the tables I am interested in and maps the expected number of rows for each table after my fixture setup has initialised the database with known data.</p>
<p>I then have the following unit test as part of this fixture:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"> <span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span>
 <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> CheckRowCountsExpected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Verifies that the correct number of rows in each database</span>
    <span style="color: #008080; font-style: italic;">// has been created as a result of the reset and test</span>
    <span style="color: #008080; font-style: italic;">// data initialisation.</span>
    AdminBll abll <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AdminBll<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    Admin<span style="color: #008000;">.</span><span style="color: #0000FF;">sysobjectsDataTable</span> tabs <span style="color: #008000;">=</span> abll<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTableRowCounts</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Admin<span style="color: #008000;">.</span><span style="color: #0000FF;">sysobjectsRow</span> trow <span style="color: #0600FF; font-weight: bold;">in</span> tabs<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
       <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>TableRowCounts<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainsKey</span> <span style="color: #008000;">&#40;</span>trow<span style="color: #008000;">.</span><span style="color: #0000FF;">TableName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
       <span style="color: #008000;">&#123;</span>
          <span style="color: #008080; font-style: italic;">//Only check the tables specified in the dictionary</span>
          Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>TableRowCounts<span style="color: #008000;">&#91;</span>trow<span style="color: #008000;">.</span><span style="color: #0000FF;">TableName</span><span style="color: #008000;">&#93;</span>,
             trow<span style="color: #008000;">.</span><span style="color: #0000FF;">RowCount</span>,
             <span style="color: #666666;">&quot;Wrong rowcount for table &quot;</span> <span style="color: #008000;">+</span> trow<span style="color: #008000;">.</span><span style="color: #0000FF;">TableName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
       <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>I also have a second test that verifies the admin query against each table one at a time using direct SELECT COUNT queries in SQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatting code in WordPress</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/11/aarrggh-formatting-code-in-wordpress/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/11/aarrggh-formatting-code-in-wordpress/#comments</comments>
		<pubDate>Thu, 11 Jan 2007 20:31:59 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=14</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/11/aarrggh-formatting-code-in-wordpress/' addthis:title='Formatting code in WordPress' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>What a pain in the rear! WordPress appears nice as a blogging tool, but my attempts to format some code snippets was painful beyond belief. Every time I pasted some code in and surrounded it with the code tags, the generated HTML had extra paragraph markers and line breaks, and screwed up the position of [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/11/aarrggh-formatting-code-in-wordpress/' addthis:title='Formatting code in WordPress' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>What a pain in the rear! WordPress appears nice as a blogging tool, but my attempts to format some code snippets was painful beyond belief.</p>
<p>Every time I pasted some code in and surrounded it with the code tags, the generated HTML had extra paragraph markers and line breaks, and screwed up the position of the closing code marker.</p>
<p>Even a search for plugins did not cure things. I installed one or two &#8220;code formatting&#8221; plugins that made things a little better, but still required a lot of post-paste editing of code to get anything like presentable.</p>
<p>It turns out that the Rich Text Editor in WordPress 2 is to blame &#8211; it completely messes up. So my advice is to disable this from your user profile.</p>
<p>The thing that rankles is that the rich editor is enabled by default. I did not even know it was optional until I did a Google on code formatting in WordPress. It all just seemed much much harder than it should.</p>
<p>Anyway, hopefully this snippet will save others the problem in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/11/aarrggh-formatting-code-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful CSV reader</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/#comments</comments>
		<pubDate>Wed, 10 Jan 2007 09:51:04 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[unit-testing]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=12</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/' addthis:title='Useful CSV reader' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>To aid my unit testing I needed to populate a database with a load of test data. This data needs to be generated by some of the less technical guys on the project and so exporting CSV (Comma Separated Values) files from Excel seemed a sensible approach. So I then cast around for any existing [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/' addthis:title='Useful CSV reader' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>To aid my unit testing I needed to populate a database with a load of test data. This data needs to be generated by some of the less technical guys on the project and so exporting CSV (Comma Separated Values) files from Excel seemed a sensible approach. So I then cast around for any existing code that would save me having to write a robust CSV parser. The search turned up this on <a href="http://www.codeproject.com/">CodeProject</a>:</p>
<p><a href="http://www.codeproject.com/cs/database/CsvReader.asp">LumenWorks.Framework </a></p>
<p>The neat thing about it is that you can get field values either by index position or column name, assuming you put column headers in your file. The column name feature really helps out with maintainance of the test data as we evolve and vary the schema slightly &#8211; we can insert columns with no worries about upsetting existing reader code.<br />
It&#8217;s easy to use and install in your own project, and the CodeProject article describes the basic usage pattern. At the moment it is just linked in to the unit test framework, but is so useful I will probably make it a part of the core application libary to facilitate importing data from customers as we anticipate some of our customers could have thousands of records to import when they move to our system.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding ASP Role tables to your own database</title>
		<link>http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/#comments</comments>
		<pubDate>Fri, 29 Dec 2006 23:17:25 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP2]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=5</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/' addthis:title='Adding ASP Role tables to your own database' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>This is still work in progress, but I want to incorporate the user role management tables within my own database, as the concept of users and their distinct roles ties right in with the core business model of the new site. The following link explains the standalone tool to create the tables: ASP.NET SQL Server [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/' addthis:title='Adding ASP Role tables to your own database' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p class="MsoNormal" style="margin-bottom: 12pt;"><span lang="EN-GB">This is still work in progress, but I want to incorporate the user role management tables within my own database, as the concept of users and their distinct roles ties right in with the core business model of the new site.<br />
The following link explains the standalone tool to create the tables:<br />
<a href="http://msdn2.microsoft.com/en-us/library/ms229862.aspx" target="_blank">ASP.NET SQL Server Registration Tool</a></span></p>
<p>Invoking the exe runs a wizard requesting the database service &#8211; it needs to match the connection string as mentioned in the gotcha above. Since no parameters are specified, it then creates a database &#8220;aspnetdb&#8221; with all the role tables. This is not quite what I want, as I need these added to my application database.</p>
<p>The answer is to use the command line:<br />
aspnet_regsql -S  -E -A all -d</p>
<p>If you run SQL Management Server Studio Express before and after &#8211; not forgetting to hit &#8216;refresh&#8217; &#8211; then a bunch of new tables are added: aspnet_Applications, aspnet_Roles, aspnet_SchemaVersions, aspnet_Users, aspnet_UsersInRoles etc. Now it is just a matter of hooking those up with the application tables.</p>
<p>Since I wanted membership and roles as well as basic authentication I used the &#8220;-A all&#8221; option to add everything in. Of course I get profile and web-part support too with this, but I may choose to exploit such features in the future.<a name="References"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

