<?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>Troy Scott's Web Blog &#187; csharp</title>
	<atom:link href="http://troyscott.ca/category/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://troyscott.ca</link>
	<description></description>
	<lastBuildDate>Mon, 17 Oct 2011 22:30:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>BDC Models in Visual Studio 2010 for SharePoint Foundation Server 2010</title>
		<link>http://troyscott.ca/2010/08/07/bdc-models-in-visual-studio-2010-for-sharepoint-foundation-server-2010/</link>
		<comments>http://troyscott.ca/2010/08/07/bdc-models-in-visual-studio-2010-for-sharepoint-foundation-server-2010/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 00:34:36 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[csharp]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://troyscott.ca/2010/08/07/bdc-models-in-visual-studio-2010-for-sharepoint-foundation-server-2010/</guid>
		<description><![CDATA[When I first started building External Content Types in (ECT) SharePoint Foundation Server I used SharePoint Designer.&#160;&#160; SharePoint Designer is a good place to start if you are learning how build ECT’s.&#160; It does not require any .NET code and you can build a fairly decent application in little time especially if you have a [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started building External Content Types in (ECT) SharePoint Foundation Server I used SharePoint Designer.&#160;&#160; SharePoint Designer is a good place to start if you are learning how build ECT’s.&#160; It does not require any .NET code and you can build a fairly decent application in little time especially if you have a solid relational database background.&#160; But I wanted to try build an External Content Type using Visual Studio 2010.&#160;&#160; In this case I am going to build a simple BDS Model based on the SalesLT.Customer table in the AdventureWorksLT2008R2 database.</p>
<p>First, lets start by creating an empty SharePoint 2010 Solution (C#)&#160; in Visual Studio 2010.&#160; Select File &gt; New &gt; Project from the file menu.&#160; In the Installed Template section under Visual C# &gt; SharePoint &gt; 2010 select the Empty SharePoint Project and name the project SPDev1.&#160; This will create an empty SharePoint project which we can add multiple projects to.</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2010/08/image7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb7.png" width="244" height="169" /></a> </p>
<p>When you select Ok the SharePoint Customization will be displayed.&#160; Enter the the site you want to use for debugging the project and make sure you select “Deploy as a farm” solution:</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2010/08/image8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb8.png" width="244" height="177" /></a> </p>
<p>Right-click on the SPDev1 project and select Add New Item:</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2010/08/image9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb9.png" width="202" height="244" /></a> </p>
<p>Now Select Business Data Connectivity Model from the Add New Item list and name it AWLTCustomer.&#160; Once you enter the name of the model click Add:</p>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb10.png" width="244" height="171" /></a></td>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb11.png" width="244" height="147" /></a></td>
</tr>
<tr>
<td valign="top" width="200"><strong>Add BDC Item</strong></td>
<td valign="top" width="200"><strong>BDC Solution</strong></td>
</tr>
</tbody>
</table>
<p>When the BDC Model is added it is fully functional.&#160; If you Build the project it will compile without any errors.&#160; </p>
<p>You will notice that I named the Blog Post <em>“BDC Models in Visual Studio 2010 for<strong> SharePoint Foundation Server 2010</strong>”&#160; </em>and not <em>“BDC Models in Visual Studio 2010 for<strong> SharePoint Server 2010</strong>”&#160; .&#160; </em>If you created this project using SharePoint Server 2010 you can actually deploy this project to the debug site and it will create an BDC Model with an entity called Entity1.&#160; But if you are using SharePoint Foundation Server 2010 you will receive the following error when the project is deployed (Right-click the project and click Deploy):</p>
<p><em><font color="#ff0000">Error&#160;&#160;&#160; 1&#160;&#160;&#160; Error occurred in deployment step &#8216;Add Solution&#8217;: Failed to load receiver assembly &quot;Microsoft.Office.SharePoint.ClientExtensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; for feature &quot;SPDev1_Feature1&quot; (ID: 1a75169a-e716-4d4b-a43c-3c0cf032fc40).: System.IO.FileNotFoundException: …</font></em></p>
<p>In order to deploy a BDC Model to Foundation Server a Feature Event Receiver is required to publish the mode to the site:</p>
<p><a href="http://code.msdn.microsoft.com/BDCSPFoundation" target="_blank">Publish BDC Model project to SharePoint Foundation 2010 with Visual Studio 2010</a></p>
<p>The following post on one of the Microsoft Blog sites provides details on how create the Feature Event Receiver.&#160; </p>
<p><a href="http://blogs.msdn.com/b/vssharepointtoolsblog/archive/2010/04/02/deploy-a-bdc-model-project-to-sharepoint-foundation-2010-using-visual-studio-2010.aspx"></a><a href="http://blogs.msdn.com/b/vssharepointtoolsblog/archive/2010/04/02/deploy-a-bdc-model-project-to-sharepoint-foundation-2010-using-visual-studio-2010.aspx" target="_blank">Deploy a BDC Model project to SharePoint Foundation 2010 using Visual Studio 2010</a></a></p>
<p>Basically you need to download the following file from the first link: </p>
<p><a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=BDCSPFoundation&amp;DownloadId=9352" target="_blank">Feature Event Receiver (C#)</a>&#160;</p>
<p>In the current project, add an Event Receiver to Feature1 by right-clicking Feature1 and select Add Event Receiver:</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2010/08/image12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb12.png" width="244" height="225" /></a>&#160;</p>
<p>First copy the existing content of Feature1.EventReceiver.cs to a file using notepad.&#160; Next, replace the contents of Feature1.EventReceiver.cs with the contents of the file downloaded from the Microsoft site (FeatureEventReceiver.cs) (Ctrl-C, Ctrl-V).&#160;&#160; The details from this point on can be found in the Microsoft Blog post mentioned above (<a href="http://blogs.msdn.com/b/vssharepointtoolsblog/archive/2010/04/02/deploy-a-bdc-model-project-to-sharepoint-foundation-2010-using-visual-studio-2010.aspx"></a><a href="http://blogs.msdn.com/b/vssharepointtoolsblog/archive/2010/04/02/deploy-a-bdc-model-project-to-sharepoint-foundation-2010-using-visual-studio-2010.aspx" target="_blank">Deploy a BDC Model project to SharePoint Foundation 2010 using Visual Studio 2010</a></a>), but I will provide some additional screenshots along with the steps.</p>
<p>We need to Add a reference to the MicrosoftBusinessData.dll. In order to do this you have to copy the dll from the GAC.&#160;&#160;&#160; Click Start &gt; Run and enter the following:</p>
<ul>
<li>C:\Windows\assembly\gac_msil </li>
</ul>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb13.png" width="244" height="128" /></a></td>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image14.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb14.png" width="244" height="136" /></a></td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>Find the Microsoft.BusinessData folder and copy the Microsoft.BusinessData.dll to the following folder:</p>
<ul>
<li>C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI </li>
</ul>
<p>Next add the following references to the project:</p>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb15.png" width="244" height="202" /></a> </td>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image16.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb16.png" width="244" height="207" /></a> </td>
</tr>
<tr>
<td valign="top" width="200"><strong><font size="1">System.Web</font></strong></td>
<td valign="top" width="200"><strong>Microsoft.BusinessData.dll</strong></td>
</tr>
</tbody>
</table>
<p>Set the BDC (SharePoint item property) which in our case is located in the AWLTCustomer model and set the following properties located under Feature Receiver Category:</p>
<ul>
<li><strong>Assembly</strong> = Assembly = $SharePoint.Project.AssemblyFullName$ </li>
<li><b>Class Name</b> = SPDev1.Features.Feature1.ImportModelReceiver </li>
</ul>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image17.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb17.png" width="244" height="240" /></a> </td>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image18.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb18.png" width="244" height="221" /></a> </td>
</tr>
<tr>
<td valign="top" width="200"><strong>Properties Before</strong></td>
<td valign="top" width="200"><strong>Properties After</strong></td>
</tr>
</tbody>
</table>
<p>Set the Feature property by double clicking on Feature1.Feature and update the following property:</p>
<ul>
<li><strong>Receiver Class</strong> = SPDev1.Features.Feature1.ImportModelReceiver </li>
</ul>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image19.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb19.png" width="244" height="219" /></a> </td>
<td valign="top" width="200"><a href="http://troyscott.ca/wp-content/uploads/2010/08/image20.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb20.png" width="244" height="221" /></a> </td>
</tr>
<tr>
<td valign="top" width="200"><strong>Properties Before</strong></td>
<td valign="top" width="200"><strong>Properties After</strong></td>
</tr>
</tbody>
</table>
<p>One last thing, we need to change the Namespace of the code that was copied into Feature1.EventReceiver.cs from BDCModelReceiver to SPDev1:</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2010/08/image21.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb21.png" width="244" height="79" /></a>&#160;</p>
<p>I have been writing this post while following&#160; Microsoft Blog.&#160; So, here is the moment of truth.&#160; After the last step we should be able to deploy the BDC model.&#160; Right-click on the project and click deploy or click F5 if you want to debug the solution.&#160; To view the content type you can open SharePoint Designer and navigate to the External Content Type sit object:</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2010/08/image22.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2010/08/image_thumb22.png" width="244" height="174" /></a> </p>
<p> Before you can create an External list based on the new External Content Type the permissions must be set.&#160; Check out this post for setting the permissions using the SharePoint Central Administration site:</p>
<p><a href="http://troyscott.ca/2010/07/09/setting-permissions-for-an-external-content-type/" target="_blank">Setting Permissions for an External Content Type</a></p>
<p>Once the permissions have been set an External List can be created.&#160; In this example the External List is very basic and in fact the model has not been connected to the External table in the Adventure Works.&#160;&#160; But that is a topic for another post.</p>
<p>For more information on BCS check the Microsoft BCS Team Blog:</p>
<p><a href="http://blogs.msdn.com/b/bcs/">http://blogs.msdn.com/b/bcs/</a></p>
<p>&#160;</p>
<p>Troy</p>
]]></content:encoded>
			<wfw:commentRss>http://troyscott.ca/2010/08/07/bdc-models-in-visual-studio-2010-for-sharepoint-foundation-server-2010/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Update requires a valid UpdateCommand when passed DataRow collection &#8230;</title>
		<link>http://troyscott.ca/2009/10/29/update-requires-a-valid-updatecommand-when-passed-datarow-collection/</link>
		<comments>http://troyscott.ca/2009/10/29/update-requires-a-valid-updatecommand-when-passed-datarow-collection/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 23:05:05 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://troyscott.ca/2009/10/29/update-requires-a-valid-updatecommand-when-passed-datarow-collection/</guid>
		<description><![CDATA[&#160; I have been creating an application for work over the last couple of days which requires ADO.Net.&#160; I work in the Business Intelligence field so I do not code verify often unless I need a custom script for an SSIS package.&#160; Most of the Microsoft BI products just require a solid understanding of SQL [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>I have been creating an application for work over the last couple of days which requires ADO.Net.&#160; I work in the Business Intelligence field so I do not code verify often unless I need a custom script for an SSIS package.&#160; Most of the Microsoft BI products just require a solid understanding of SQL or MDX and of course the customers business requirements.&#160;&#160; While creating the application I ran into the following error when updating the databases with changes in the dataset.&#160; I am using Visual Studio 2008 Express Edition and the database is a Compact Database.&#160; </p>
<p>I only received the error when I tried to update a record in the database.&#160; If I added a new record (INSERT) and saved my changes the application worked fine.&#160; Below is a screenshot of the simple app:</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2009/10/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2009/10/image-thumb.png" width="291" height="206" /></a>&#160;</p>
<p>When you hit the save button it executes the following code:</p>
<p><font size="1" face="Courier New">try     <br />{      <br />&#160; </font><font size="1"><font face="Courier New"><em>this.Validate();         <br /></em>&#160; this.rulesBindingSource.EndEdit();        <br />&#160; this.rulesTableAdapter.Update(this.ruleEngineDataSet.Rules); </font></font></p>
<p><font size="1" face="Courier New">&#160; MessageBox.Show(&quot;Update successful!&quot;); </font></p>
<p><font size="1" face="Courier New">}</font></p>
<p><font size="1" face="Courier New">catch (System.Exception ex)     <br />{      <br />&#160; MessageBox.Show(&quot;Update failed:\n&quot; + ex.Message + &quot;\n&quot; + ex.StackTrace ); </font></p>
<p><font size="1" face="Courier New">}</font></p>
<p><font face="Trebuchet MS">I placed a breakpoint on: <em>this.Validate();</em> line.&#160; When I ran the program&#160; the program failed on: <em>this.rulesTableAdapter.Update(this.ruleEngineDataSet.Rules);.&#160; </em>Below is a print screen of the message:</font></p>
<p>&#160;</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2009/10/image1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2009/10/image-thumb1.png" width="303" height="66" /></a>&#160;</p>
<p>The issue is with the TableAdapter.&#160; There was no UpdateCommand (which is mentioned in the error message) or DeleteCommand for the TableAdapter:</p>
<p>&#160;<a href="http://troyscott.ca/wp-content/uploads/2009/10/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2009/10/image-thumb2.png" width="302" height="155" /></a> </p>
<p>Create a new UpdateCommand by click (new) in the dropdown box.&#160; You can use the query designer to create the update statement for the CommandText property:</p>
<p><a href="http://troyscott.ca/wp-content/uploads/2009/10/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://troyscott.ca/wp-content/uploads/2009/10/image-thumb3.png" width="244" height="220" /></a> </p>
<p>Once the the CommandText property was set for the UpdateCommand the program worked. Below is a link to the issue found on msdn forums:</p>
<p><a title="http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/6d4de721-7571-49ca-a1fc-8689ec19a94e/" href="http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/6d4de721-7571-49ca-a1fc-8689ec19a94e/">http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/6d4de721-7571-49ca-a1fc-8689ec19a94e/</a></p>
<p>Troy</p>
]]></content:encoded>
			<wfw:commentRss>http://troyscott.ca/2009/10/29/update-requires-a-valid-updatecommand-when-passed-datarow-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

