<?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>nPath Ltd. &#187; Formview</title>
	<atom:link href="http://www.npathweb.com/tag/formview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.npathweb.com</link>
	<description>Web Development Blog</description>
	<lastBuildDate>Mon, 22 Feb 2010 15:16:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Insert with FormView using Linq</title>
		<link>http://www.npathweb.com/2009/02/05/insert-with-formview-using-linq/</link>
		<comments>http://www.npathweb.com/2009/02/05/insert-with-formview-using-linq/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 17:05:40 +0000</pubDate>
		<dc:creator>B.Harding</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[Formview]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.npathweb.com/blog/?p=23</guid>
		<description><![CDATA[I had a wierd error trying to insert data using a formview today.
The jist is this: the formview was trying to use an empty string for an int field instead of Nothing.
Here is the error I saw, helpful huh?

Failed to set one or more properties on type xxxxxxx  Ensure that the input values are valid and can [...]]]></description>
			<content:encoded><![CDATA[<p>I had a wierd error trying to insert data using a formview today.</p>
<p>The jist is this: the formview was trying to use an empty string for an int field instead of Nothing.<br />
Here is the error I saw, helpful huh?</p>
<p><span></p>
<h2><em><span style="color: #a52a2a;">Failed to set one or more properties on type xxxxxxx  Ensure that the input values are valid and can be converted to the corresponding property types.</span></em></h2>
<p></span></p>
<p>The fields are allowed to be null but the formview just isn&#8217;t smart enough to use nothing instead of &#8220;&#8221;.</p>
<p>My workaround was simple and flexible enough to be re-used so I figured I would post it here.<br />
I simply hijack the formview&#8217;s onInserting and replaced &#8220;&#8221; with Nothing for each field.</p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">Protected</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span><span style="font-size: x-small;"> formView1_ItemInserting(</span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> sender </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Object</span><span style="font-size: x-small;">, </span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> e </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> System.Web.UI.WebControls.FormViewInsertEventArgs)</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;"> For</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Each</span><span style="font-size: x-small;"> o </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> DictionaryEntry </span><span style="color: #0000ff; font-size: x-small;">In</span><span style="font-size: x-small;"> e.Values<br />
</span><span style="color: #0000ff; font-size: x-small;">If</span><span style="font-size: x-small;"> o.Value = </span><span style="color: #a31515; font-size: x-small;">&#8220;&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Then</span><span style="font-size: x-small;"> e.Values(o.Key) = </span><span style="color: #0000ff; font-size: x-small;">Nothing<br />
</span><span style="color: #0000ff; font-size: x-small;"> Next</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.npathweb.com/2009/02/05/insert-with-formview-using-linq/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
