<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/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>Smart Client Data : Blogicles</title><link>http://blogs.msdn.com/smartclientdata/archive/tags/Blogicles/default.aspx</link><description>Tags: Blogicles</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Splitting Typed DataSets from TableAdapters - Sharing Validation Code across the tiers</title><link>http://blogs.msdn.com/smartclientdata/archive/2006/02/21/SeperatingTypedDataSetsFromTableAdapters.aspx</link><pubDate>Tue, 21 Feb 2006 21:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:536217</guid><dc:creator>Steve.Lasker</dc:creator><slash:comments>17</slash:comments><comments>http://blogs.msdn.com/smartclientdata/comments/536217.aspx</comments><wfw:commentRss>http://blogs.msdn.com/smartclientdata/commentrss.aspx?PostID=536217</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Tahoma&gt;You’re building a Smart Client application.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You want this Smart Client to be smart enough to provide validation feedback to the user as they enter information.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;However, in order to make the application scale to thousands of users you can’t open connections directly to the database from the client because you’re server can’t handle that many connections.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You probably don’t want the data access information to be available on the client anyway so you turn to Web Services to help abstract the intimate knowledge about your database.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This way the client only has Web Service address and authentication information.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Since web services can be consumed by many different types of clients you don’t want to trust that all the validation rules have been enforced.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;So, what do you do?&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in" type=disc&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo7; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;You could put all the validation rules in the database, but that means your database has that much more processing to do, and your Smart Client won’t be so smart.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;It will still have to make round trips to the database each time a user tabs off a control.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo7; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;You could use the XSD schema validation extensions, but they aren’t all that extensible and they don’t deal with dynamic values.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo7; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;You could write the validation code twice.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Once for the server, then again for the client.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;But that wouldn’t be all that maintainable.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;The likely solution is to simply write the validation logic and share it on the client and within the web service.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;But wait, that’s type sharing… that’s bad…&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Well, yes and no.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In the old days of COM/DCOM and even with Remoting you really were sharing the same actual object.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The client would instantiate a component and it would actually run on a remote server.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In addition to scalability issues, this also had a maintenance issue.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;If you ever updated the component on the server, even if it didn’t involve changing the public interface, all the clients had to be updated as well.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;To make this more complicated, since clients are running statefull operations on shared servers you usually had to completely shut down the entire system to make a simple update.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Web Services solves these problems as the object being used and what travels across the wire are really individual things.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The serialization format of a particular object has no real direct correlation to the actual object.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Yes, certain objects serialize certain types of formats, but that’s not a hard and fast rule.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;I can talk in English, French, German, Hungarian, but I’d still be saying the same thing.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Likewise, 3 different people can all say the same thing in English, and it would have the same meaning.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Once you separate the wire protocol from the functionality you can change the internal implementation all you want, and as long as you don’t change the public interface and your clients can continue to consume the service.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;Now I know that many would argue that changing functionality within a service is breaking the contract.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;And to some extent you’re correct.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;If you’re exposing a public service, and don’t own all the clients then you do have an obligation to maintain consistency.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;However, if you do own the clients and the services are only consumed as part of your application then this becomes a very flexible model.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;Take the following scenario:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;You roll out your application over the weekend.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Thousands of users fire up the app first thing Monday morning.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;They all get the updated version with ClickOnce deployment.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Life is good.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Later that day you notice that you forgot to put a validation rule in that all orders can’t be shipped for 7 days after the order date.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You quickly add the validation rule to enforce DueDate must be Today + 7 Days and you add a default value that DueDate is Today + 7 days, but how do you deploy this?&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You could announce over the PA system that everyone must exit the sales system for 5 minutes which effectively shuts the company down and directly affects the profits of the day. That probably wouldn’t reflect well on your next review.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;Or, you could update the validation logic on the server without touching the client.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Since the public interface didn’t change, the clients continue to function.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Since ASP.net Web Services use something called Shadow Copied assemblies, you aren’t blocked from updating an assembly in the web server.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Once the file is finished being copied, the webserver detects that one of the assemblies that’s using has changed and reloads that assembly into memory. The next request will immediately get the new functionality.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;At this point the client doesn’t have the validation logic, however, when the sales rep attempts to save an order the additional validation logic will kick in and send back the error to the client.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;If the developer updated the client app with the new assembly then the clients will get updated the next time they restart their app.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;You could use the ClickOnce background APIs to constantly check for updates, and that’s a good thing but you don’t want to be checking or updates ever 10 seconds.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;That sort of defeats the purpose here.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In the above example, you were able to immediately affect a change without interrupting any of the sales reps which means no downtime, and you’ve got a great review again.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;So, how do you implement all this?&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The basic concepts, including some of the proxy generation issues of Web Services equally apply to custom objects, but for this article I’ll focus on how to leverage Typed DataSets to enable validation on the client but enforce it on the server.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;One of the major features of Visual Studio 2005 is the new typed data access components called TableAdapters.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;These can be used within your Data Access Layer to handle all the CRUD operations to the database.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;TableAdapters are effectively strongly typed DataAdaters.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;These bring parity with the Typed DataSet experience in Visual Studio 2002.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;One of the VS 2005 enhancements of Typed DataSets is the use of partial classes.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In 2002/03 it was very difficult to add custom logic to the Typed DataSet.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Since Visual Studio uses something called Single File Generators to generate the Typed Datasets, any code the developer added to the Typed DataSet would be lost the next time the generator ran.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Developers would sometimes inherit from the Typed DataSet but that had lots of other complications as well.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;It further complicated things as you now had two types; the one generated by Visual Studio and the one that had your validation code.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;Visual Studio 2005 Typed DataSets leverage a feature known as partial classes.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Using partial classes developers can now directly enhance the functionality of the generated Typed DataSet without the possibility of being overwritten by the Single File Generator.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This means we can now easily add our validation code directly to the Typed DataSet and enforce it on the server.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;However, because Visual studio generates the Typed DataSet in the same file and project as the TableAdapters we don’t have an easy way to leverage the Typed DataSet on the client.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;We could add a reference to the assembly that contains the Typed DataSet and TableAdapters on the client, but now the client has the intimate knowledge of the server that we’re trying to avoid?&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;Great, so now what?&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Well, it turns out it’s not all that difficult to separate these.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;It’s not very discoverable, but it’s not that difficult.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;What we’re going to do is separate the Typed DataSet from the DataLayer into its own DataEntities assembly.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;We’ll create a Web Service to return the Typed DataSet and use the DataLayer assembly behind the web service.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The client application will share the reference to the DataEntities assembly on the client but it won’t have the DataLayer so we’ll keep the intimates of the database away from the client.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Since Web Services serializes DataSets as XML we can leverage the same type on both sides of the wire, but we’re not actually sharing the same instance so we get a lot of flexibility in how we update the application.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;The rest of this article focuses on a walkthrough for how to accomplish this.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;I’ll highlight some of the best practices for this scenario to minimize complexities for working around the default behavior of the tool.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;To get things started we’ll create a solution with the projects to represent the logical and physical tiers.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Creating the solution&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l8 level2 lfo1; tab-stops: list .25in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;FONT face=Tahoma&gt;Using Visual Studio 2005 create a new solution containing 4 projects.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;It doesn’t matter whether you’re using VB or C#.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 89.6pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=119&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Project Name&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #ece9d8; WIDTH: 353.2pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top width=471&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Project Type &amp;amp; Description&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 1"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 89.6pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=119&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;Client&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #ece9d8; WIDTH: 353.2pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=471&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;A Windows Forms project&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 2"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 89.6pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=119&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;DataEntities&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #ece9d8; WIDTH: 353.2pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=471&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;A Class Library that will contain our Typed DataSet with validation logic&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 3"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 89.6pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=119&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;DataLayer&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #ece9d8; WIDTH: 353.2pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=471&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;A Class Library that will load and save the Typed DataSet in the DataEntities dll&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 4; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 89.6pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=119&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;BizServices&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #ece9d8; WIDTH: 353.2pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=471&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;A WebService that will simply wrap calls to the DataLayer&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l8 level2 lfo1; tab-stops: list .25in"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Tahoma&gt;Delete Class1 in the Class Libraries&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l8 level2 lfo1; tab-stops: list .25in"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;3.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Tahoma&gt;Delete the Service.asmx and Service.vb/cs file in the App_Code directory&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l8 level2 lfo1; tab-stops: list .25in"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;4.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Tahoma&gt;You should now have a solution that looks something like the following:&lt;/FONT&gt;&lt;/P&gt;&lt;IMG src="http://windowsforms.net/Presentations/BlogImages/DataSetTableAdapterSplit/SharedDataEntitiesEmptySolution.JPG"&gt; 
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Adding a Typed DataSet/TableAdapters to the DataLayer&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l6 level1 lfo2; tab-stops: list .25in"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Tahoma&gt;With the DataLayer selectged, open the Data Sources Window. (You can do this using the Data Menu and select Show Data Sources).&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l6 level1 lfo2; tab-stops: list .25in"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Tahoma&gt;Add a new Data Source and choose Database&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l6 level1 lfo2; tab-stops: list .25in"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;3.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Tahoma&gt;Add a connection to your database.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In this walkthrough we’ll use the Northwind database&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l6 level1 lfo2; tab-stops: list .25in"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;4.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Tahoma&gt;Using the treeview, choose your tables.&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;We’ll simply select the Orders table for this walkthrough.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You could use sprocs or views, but to keep this walkthrough focused, we’ll just select the orders table and press finish.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l6 level1 lfo2; tab-stops: list .25in"&gt;&lt;SPAN style="mso-fareast-font-family: Tahoma; mso-bidi-font-family: Tahoma"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Tahoma&gt;5.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Tahoma&gt;You should now have a Typed DataSet and TableAdapter for the Northwind.Orders table&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;IMG src="http://windowsforms.net/Presentations/BlogImages/DataSetTableAdapterSplit/SharedDataEntities-DataSet.JPG" __designer:dtid="281474976710839"&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Moving the DataSet to the DataEntities project&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;We’ll now cut and paste the Typed DataSet definition from the DataLayer to the DataEntities project to isolate the intimate knowledge of the database from the data entities.&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l7 level1 lfo3; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Show the hidden files by pressing “Show All Files” button in the top of the solution explorer&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l7 level1 lfo3; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Open the NorthwindDataSet.Designer.vb/cs file&lt;BR&gt;In this file you’ll see two major sections.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The definition of the Typed DataSet and a namespace for all the TableAdapters associated with the Typed DataSet&lt;BR&gt;It’s easiest to see the source if you collapse the regions for the Typed DataSet and the TableAdapter namespace&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;IMG src="http://windowsforms.net/Presentations/BlogImages/DataSetTableAdapterSplit/SharedDataEntities-DataSetSource.JPG"&gt; 
&lt;OL style="MARGIN-TOP: 0in" type=1 start=3&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l7 level1 lfo3; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Copy the source code from the first line through the definition of the Typed DataSet&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l7 level1 lfo3; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In the DataEntities project add a new Class File and name it the same as your DataSet.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You’ll want to add the .Designer extension to maintain separation between the generated code and the validation code we’ll add later on.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In this case we’ll create &lt;B style="mso-bidi-font-weight: normal"&gt;NorthwindDataSet.Designer.vb&lt;/B&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l7 level1 lfo3; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In this file paste over the entire contents with the source you copied from the DataLayer.dll&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l7 level1 lfo3; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Back in the DataLayer project, delete the DataSet definition.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Be sure to leave the headers, Imports and if using VB, the Option Strict code &lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Fixing up the references&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;If you build the project you’ll now see a bunch of errors in the task list.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The TableAdapters reference a type that is no longer “visible”.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo8; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In the DataLayer project, add a reference to the DataEntities project.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This will solve the issue of finding the types.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo8; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;You’ll now need to add a project level imports to resolve any namespace differences between the entities and DataLayer.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;VB&lt;/B&gt;: Select the DataLayer project and double click the My Project node to open the Project Properties.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Select the References tab and using the Imported Namespaces check the DataEntities namespace.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The errors should now disappear from the task list.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face=Tahoma&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;C#&lt;/B&gt;: Open the NorthwindDataSet.Designer.cs file and add an additional Using statement for the DataEntities project: &lt;BR&gt;using DataEntities;&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=3&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo8; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Once you build the solution you should no longer see any build errors.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;We now have data access and data entities isolated and the have the proper references. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Notice that while the DataLayer does have a reference to the DataEntites the opposite is not true. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This means the DataEntiteis can be used without any database intimates. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;The next problem is how to get the DataEntites from the DataLayer to the client. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This is where Web Services come in.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Using Web Services we can abstract the client form the server logic. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Note that this same process will work for the upcoming Windows Communication Framework in WinFX.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Exposing the DataEntities via Web Services&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;In order to expose the DataEntities via Web Service we’ll create some thin wrappers to delegate any calls to the DataLayer&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l4 level1 lfo4; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In the BizServices web service project select add new Web Service &lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l4 level1 lfo4; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Name the Web Service &lt;B style="mso-bidi-font-weight: normal"&gt;Orders&lt;/B&gt;.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Visual Studio will create two files.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;One for IIS to expose as an address, Orders.asmx.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;And another for the code, Orders.vb/cs&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l4 level1 lfo4; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In the BizServices project add references to the DataEntities and the DataLayer projects.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l4 level1 lfo4; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In the Orders.vb/cs file add the following code to expose the Load and Save methods:&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; _ordersTableAdapter &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; DataLayer.NorthwindDataSetTableAdapters.OrdersTableAdapter&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt;()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;_ordersTableAdapter = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; DataLayer.NorthwindDataSetTableAdapters.OrdersTableAdapter()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;WebMethod()&amp;gt; _&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; GetOrders() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; DataEntities.NorthwindDataSet.OrdersDataTable&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; _ordersTableAdapter.GetData()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;WebMethod()&amp;gt; _&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; SaveOrders(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; orders &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; DataEntities.NorthwindDataSet.OrdersDataTable) &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; DataEntities.NorthwindDataSet.OrdersDataTable&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; orders.HasErrors &lt;SPAN style="COLOR: blue"&gt;Then&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; orders&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Else&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;_ordersTableAdapter.Update(orders)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; orders&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=5&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l4 level1 lfo4; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;We now have the ability to return and save Orders to the database.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The sample above does do some validation testing within the web service which you’d likely want to place in a separate assembly. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;You could place it in the DataLayer as well&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The point is you want to minimize the actual code in the Web Services project so you’ll have more flexibility for where to use this code. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;For instance, when WCF ships you’ll likely want to leverage some of the new transports. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;By keeping the code in the web service to an absolution minimum you’ll ease your migration process.. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR&gt;Another thing worth notice is while this sample focuses on a simple 1:1 mapping of the database to the returned DataSet, that isn’t the limitation of DataSets.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The TableAdapter wizards are optimized for relatively simple mappings, but using ADO.net commands, Stored Procedures and/or Views, you can do quite a bit of additional logic to differentiate the schemas of your DataSet from the underlying database.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Using the merge capabilities of DataSet, you can have a single DataSet or even a single DataTable represent data from two or more database systems.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;But, that’s a discussion for another day.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Consuming the DataEntities in your WinForms client&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;FONT face=Tahoma&gt;We’ll now add the ability to load and save a form full of customers. In the client project we’ll add a Web reference to our BizServices to get the load and save functionality and we’ll add an additional reference to the DataEntities dll.to leverage common validation logic on the client and the server. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Note that we won’t have any reference to the DataLayer dll so the client will be clean of data access knowledge.&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo5; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Using Solution Explorer select Add Web Reference in the Client project.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You could use the Data Sources Window, but we’ll want to rename the service and this feature isn’t available in the Data Sources Window wizard.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo5; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In the Web Reference wizard browse Web services in this solution.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You should now see your Orders service.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo5; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Since LocalHost is fairly meaningless, select the Orders Service and rename it OrdersService.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Press finish to continue&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo5; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;If you notice the Data Sources Window you’ll see the dataset returned by the web service is now available.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;What’s important to note is while this dataset is the same “shape” as the data set returned by the Web Service, it’s not the same Type as the DataSet in the DataEntities project.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The Web Reference Dialog created a proxy type for the dataset.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;If you show the hidden files you can navigate through the OrdersService, Reference.map to find the refernce.vb file.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This contains the code necessary to call the OrdersService, but it also contains a type definition for the NorthwindDataSet.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;While it is declared as Partial, we’re not going to leverage this feature.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;&lt;IMG src="http://windowsforms.net/Presentations/BlogImages/DataSetTableAdapterSplit/SharedDataEntities-WebServiceProxy.JPG"&gt; &lt;BR&gt;Due to time constraints in the Visual Studio 2005 schedule we were unable to complete a feature we refer to as Proxy Type Sharing.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;If you consume multiple web services from the same project that return the same type, Visual Studio will create multiple proxy types on the client.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This means you could actually wind up with several TypedDataSets on the client that all share the same shape.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;However, even if we fixed Proxy Type Sharing, we still wouldn’t have exactly what we need in this scenario. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;In this case, we already have the type on the client, so we don’t need a proxy. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;In a few steps, we’ll see how we consolidate these.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Merging the proxy and original types&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;FONT face=Tahoma&gt;Although we’ll use the Web Service to get and save orders, we’re not going to use this TypedDataSet to represent our data within our client app.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Instead we’re going to use the DataEntities dataset&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo9; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;With the Client project active, use the Data Sources Window to add an Object Data Source.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Add a reference to the DataEntities project and select the NorthwindDataSet as your Object DataSource.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;Visual studio differentiates Object Data Sources from Database DataSources by providing a different design experience.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;When the developer chooses Database datasources, Visual Studio creates Typed DataSets and TableAdapters.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;When you drag &amp;amp; drop Database DataSources from the Data Sources Window Visual Studio will add additional load and save code to your form.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For Object Data Sources, Visual Studio doesn’t make any assumptions about how you load and save your objects.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Typed DataSets are simply very specialized data object containers that have all the necessary plumbing for serializing and databinding.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo9; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;With Form1 open, select the DataEntities.Northwind.Orders object in the Data Sources Window and drag it to the form.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Be sure you’re getting the right DataSet, it can be confusing as they’re both named similarly.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;
&lt;OL style="MARGIN-TOP: 0in" type=a&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level2 lfo9; tab-stops: list 1.0in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT face=Tahoma&gt;You can remove the Web Service DataSet proxy from the Data Sources Window with a little work around. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;If you show hidden files in the Client project and navigate through OrdersService -&amp;gt; Reference.map you’ll see a NorthwindDataSet.datasource file. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This file is what Visual Studio uses to show object in the Data Sources Window. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;If you delete this file the entry will be removed from the Data Sources Window but the Web Service will still exist. If you ever update the web reference the .datasource file will be recreated.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo9; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Double click the form to get the form.load event and add the following code to merge the DataSet returned by the web service with the DataEntities DataSet. &lt;/FONT&gt;
&lt;OL style="MARGIN-TOP: 0in" type=a&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level2 lfo9; tab-stops: list 1.0in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT face=Tahoma&gt;We could do another work around and change the code generated by the web service proxy generator, however this is much more complicated to maintain. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Since DataSets and DataTables support merge capabilities, we can avoid changing the generated code. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;For plain old objects, (POOs) that don’t support merge capabilities, you’ll likely want to edit the proxy generated code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Form1_Load(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.Load&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.NorthwindDataSet.Orders.Merge(&lt;SPAN style="COLOR: blue"&gt;My&lt;/SPAN&gt;.WebServices.Orders.GetOrders())&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT face=Tahoma&gt;Notice that DataTables now support merging directly.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In 1.x, you had to merge the entire DataSet.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Also note that we were able to return an individual Typed DataTable rather then the entire DataSet.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This only works for Typed DataTables,&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You can’t return a single UnTyped DataTable&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=4&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo9; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Activate the form designer again and enable the Save button that was created in the BindingNavigatgor&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo9; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Double click the Save button and add the following code to commit any changes made by the user and send the changes to the server.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; OrdersBindingNavigatorSaveItem_Click(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; OrdersBindingNavigatorSaveItem.Click&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Validate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.OrdersBindingSource.EndEdit()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; orderServiceOrderTable &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Client.OrdersService.NorthwindDataSet.OrdersDataTable()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;orderServiceOrderTable.Merge(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.NorthwindDataSet.Orders.GetChanges())&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;orderServiceOrderTable = &lt;SPAN style="COLOR: blue"&gt;My&lt;/SPAN&gt;.WebServices.Orders.SaveOrders(orderServiceOrderTable)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; orderServiceOrderTable.HasErrors &lt;SPAN style="COLOR: blue"&gt;Then&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;MessageBox.Show(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;"Errors on attempt to save"&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.NorthwindDataSet.Orders.Merge(orderServiceOrderTable)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=6&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo9; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Hit F5 to run you’re app&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo9; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;If you look in the bin directory of the Client app you’ll notice we only have the DataEntities.dll and Client.exe files.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The DataLayer which contains all the intimate knowledge of the Databas are left out of the picture.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo9; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Using ClickOnce, publish the Client project and install it on your machine.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Be sure to use the default behavior so you get the Start menu item&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Adding Validation Code&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;FONT face=Tahoma&gt;Now that we’ve got the client project setup and deployed, let’s add some validation logic.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In order to demonstrate the lack of tight coupling, we’ll add the validation logic to the DataEntities project, but we won’t actually deploy this to the client.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;So, when testing this, be sure not to republish the client.&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo6; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In the DataEntities project add a new class file.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Name it NorthwindDataSet.vb/cs.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Note that we’re using the same standard as forms and the DataSet designer to isolate designer generated code from your code.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo6; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;In the file add the following code:&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; OrdersDataTable_ColumnChanged(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Data.DataColumnChangeEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.ColumnChanged&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' We use the Changed event as we try to avoid deleting information a user enters&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' Rather we show them what they typed, but provide information indicating the specific error&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' This helps users understand if they mistyped, or the information is just not permitted&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' Use strongly typed names of the columns to benefit from compile time verification &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' If the user changed the OrderDate or ShippedDate columns, verify the dates&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.Column.ColumnName = &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.OrderDateColumn.ColumnName &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; _&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;e.Column.ColumnName = &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.ShippedDateColumn.ColumnName &lt;SPAN style="COLOR: blue"&gt;Then&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&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; &lt;/SPAN&gt;ValidateDates(e.Row)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; ValidateDates(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; row &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; OrdersRow)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' Check for specific column errors and set or clear the errors&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' Using this model, DataSets will surface the errors using the IDataError interface&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' DataBinding in the DataGridView and ErrorProvider will pick up these errors&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' and surface them to the user&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' You may want to use strongly typed Resources for the error strings.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; row.OrderDate &amp;gt; row.ShippedDate &lt;SPAN style="COLOR: blue"&gt;Then&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&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; &lt;/SPAN&gt;row.SetColumnError(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.OrderDateColumn, &lt;SPAN style="COLOR: maroon"&gt;"Can't ship before it's been ordered"&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&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; &lt;/SPAN&gt;row.SetColumnError(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.ShippedDateColumn, &lt;SPAN style="COLOR: maroon"&gt;"Can't ship before it's been ordered"&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Else&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&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; &lt;/SPAN&gt;row.SetColumnError(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.OrderDateColumn, &lt;SPAN style="COLOR: maroon"&gt;""&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&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; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;row.SetColumnError(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.ShippedDateColumn, &lt;SPAN style="COLOR: maroon"&gt;""&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=3&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo6; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Rebuild the entire solution to make sure the updated DataEntites dll gets pushed up to the Web Service project.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo6; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;With the app still running, change the OrderDate to be after the ShippedDate.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Note that if you closed the app from above, simply start it again from the start menu so you get the version that doesn’t have the updated DataEnties on the client.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Notice that you don’t see any errors in the DataGridView. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo6; tab-stops: list .5in"&gt;&lt;FONT face=Tahoma&gt;Press the save button.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You may notice a slight delay as the Web Service re-computes the updated assembly, but when it returns you should now see ErrorProviders indicating that the ShipDate can’t be before the OrderDate. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Updating the client&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;To update the client, simply republish the Client project using the ClickOnce deployment wizard and restart your client app. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Wrapping Up&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;With the above scenarios you were able to make changes to the DataEntities without breaking the client applications. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;You’re users maintained their productivity, yet you were able to quickly add new validation rules. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;The clients could then be updated to complete the update, but you didn’t break you’re users workflow in the process. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;With the basic tooling support in Visual Studio and these tricks you can achieve a truly factored ‘N scale application that leverages code where you want, scales to thousands of users, can be updated mid day without kicking your users off the system and delivers on the promise of Smart Clients for productive users.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Tahoma&gt;Post Whidbey, we are working to enable this scenario without all the work arounds noted above, but for now…&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;&lt;/FONT&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Tahoma&gt;Steve&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Tahoma&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=536217" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Blogicles/default.aspx">Blogicles</category><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Whidbey+Q+_2600_+A/default.aspx">Whidbey Q &amp; A</category></item><item><title>Working with local databases</title><link>http://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx</link><pubDate>Fri, 26 Aug 2005 23:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:456886</guid><dc:creator>SmartClientData</dc:creator><slash:comments>49</slash:comments><comments>http://blogs.msdn.com/smartclientdata/comments/456886.aspx</comments><wfw:commentRss>http://blogs.msdn.com/smartclientdata/commentrss.aspx?PostID=456886</wfw:commentRss><description>&lt;B&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Overview&lt;/FONT&gt;&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;In Visual Studio 2005 we added a number of features to help developers build and deploy applications that need a local data store. Here's a quick peek at how it works.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;In order to work with a local database file, you can simply add the file to your project (e.g. using the Project/Add Existing Item... menu). We currently support adding SQL Server data files (.mdf), Jet (Access) data files (.mdb) and&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;SQL Mobile data files (.sdf). Note that in order to be able to use .mdf files, you need to have installed SQL Server Express. SQL Express is available on the VS CD or at &lt;A href="http://go.microsoft.com/fwlink/?LinkId=49251"&gt;http://go.microsoft.com/fwlink/?LinkId=49251&lt;/A&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;. With SQL Server Express installed, you will also be able to create new databases through 'Project/Add New Item…/Database'.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Once the database file is in the project, VS will do a few things:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1. It will automatically add a connection in the Database Explorer so you can edit the database schema or the data.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2. It will make sure that the connection strings are serialized using a relative path (more on this below).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3. The first time the file is added, VS will also launch the Data Source wizard to create a new typed dataset.&lt;/FONT&gt;&lt;/P&gt;&lt;B&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Full path vs relative path&lt;/FONT&gt;&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;One of the reasons why it was hard to work with database files before is that the full path to the database was serialized in different places. This made it harder to share a project and also to deploy the application. In this version, the .NET runtime added support for what we call the DataDirectory macro. This allows&amp;nbsp;Visual Studio&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Arial&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;to put a special variable in the connection string that will be expanded at run-time. So instead of having a connection string like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Data Source=.\SQLExpress;AttachDbFileName=c:\program files\app\data.mdf"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;You can have a connection string like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Data Source=.\SQLExpress;AttachDbFileName=|DataDirectory|\data.mdf"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;This connection string syntax is supported by the SqlClient and OleDb managed providers. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;By default, the |DataDirectory| variable will be expanded as follow:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - For &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;applications placed in a directory on the user machine, this will be the app's (.exe) folder.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT face=Arial&gt;- For apps running under ClickOnce, this will be&amp;nbsp;a special &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;data folder created by ClickOnce&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT face=Arial&gt;- For Web apps, this will be the App_Data folder&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Under the hood, the value for |DataDirectory| simply comes from a property on the app domain. It is possible to change that value and override the default behavior by doing this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AppDomain.CurrentDomain.SetData("DataDirectory", newpath)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;For customizing the connection string at runtime, please see our team blog at: &lt;a href="http://blogs.msdn.com/smartclientdata/archive/2005/07/25/443034.aspx"&gt;http://blogs.msdn.com/smartclientdata/archive/2005/07/25/443034.aspx&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;B&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Where is my data? -- Understanding the file copy for desktop projects&lt;/FONT&gt;&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;One of the things to know when working with local database files is that they are treated as any other content files. For desktop projects, it means that by default, the database file will be copied to the output folder (aka bin) each time the project is built. After F5, here's what it would look like on disk&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyProject\Data.mdf&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyProject\MyApp.vb&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyProject\Bin\Debug\Data.mdf&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyProject\Bin\Debug\MyApp.exe&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;At design-time, MyProject\Data.mdf is used by the data tools. At run-time, the app will be using the database under the output folder. As a result of the copy, many people have the impression that the app did not save the data to the database file. In fact, this is simply because there are two copies of the data file involved. Same applies when looking at the schema/data through the database explorer. The tools are using the copy in the project, not the one in the bin folder.&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;If this copy behavior is not what you want, there are few ways to work around it:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;1. If you select local database file in the Solution Explorer window, you will see a property called ‘Copy to Output’ in the Properties window. By default it is set to ‘Copy Always’ which means that on each build, the data files in the project folder will be copied to the output folder overwriting the existing data files if any. You can set this property to Copy Never and then manually put a copy of the data file in the output folder. This way, on subsequent builds, the project system will leave the datafile in the output folder and not try to overwrite it with the one from the project. The downside is that you still have two copies so after you modify the database file using the app, if you want to work on those changes in the project, you need to copy it to the project manually and vise-versa.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;2. You can leave the data file outside the project and create a connection to it in Database Explorer. When the IDE asks you to bring the file into the project, just say no. This way, both the design-time and the run-time will be using the same data file but the downside is that the path in the connection string will be hard coded and therefore it’ll be harder to share the project and deploy the app. Before deploying the app, just make sure to replace the full path in the settings with a relative path.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Antoine&lt;BR&gt;Software Design Engineer&lt;BR&gt;Visual Studio Data Design-time&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=456886" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Blogicles/default.aspx">Blogicles</category><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Whidbey+Q+_2600_+A/default.aspx">Whidbey Q &amp; A</category></item><item><title>Drag Once w/Custom Controls</title><link>http://blogs.msdn.com/smartclientdata/archive/2005/08/24/455568.aspx</link><pubDate>Wed, 24 Aug 2005 17:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:455568</guid><dc:creator>SmartClientData</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/smartclientdata/comments/455568.aspx</comments><wfw:commentRss>http://blogs.msdn.com/smartclientdata/commentrss.aspx?PostID=455568</wfw:commentRss><description>&lt;P&gt;Article written for CoDe magazine describing how to customize the controls listed in the Data Sources Window for Drag Once Databinding&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.code-magazine.com/Article.aspx?quickid=0411071"&gt;http://www.code-magazine.com/Article.aspx?quickid=0411071&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=455568" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Blogicles/default.aspx">Blogicles</category><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Whidbey+Q+_2600_+A/default.aspx">Whidbey Q &amp; A</category></item><item><title>Drag Once Databinding</title><link>http://blogs.msdn.com/smartclientdata/archive/2005/08/24/455566.aspx</link><pubDate>Wed, 24 Aug 2005 17:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:455566</guid><dc:creator>SmartClientData</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/smartclientdata/comments/455566.aspx</comments><wfw:commentRss>http://blogs.msdn.com/smartclientdata/commentrss.aspx?PostID=455566</wfw:commentRss><description>&lt;P&gt;Article written for CoDe magazine relating to the Drag Once Databinding features in Smart Client Applicaitons&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.Code-Magazine.com/Article.aspx?quickid=0409051"&gt;www.Code-Magazine.com/Article.aspx?quickid=0409051&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=455566" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Blogicles/default.aspx">Blogicles</category><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Whidbey+Q+_2600_+A/default.aspx">Whidbey Q &amp; A</category></item><item><title>The little database that could.  Deploying SQL Mobile as a local / single user database across Microsoft Mobile devices</title><link>http://blogs.msdn.com/smartclientdata/archive/2005/07/15/439008.aspx</link><pubDate>Fri, 15 Jul 2005 02:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:439008</guid><dc:creator>SmartClientData</dc:creator><slash:comments>35</slash:comments><comments>http://blogs.msdn.com/smartclientdata/comments/439008.aspx</comments><wfw:commentRss>http://blogs.msdn.com/smartclientdata/commentrss.aspx?PostID=439008</wfw:commentRss><description>The little database that could.  Deploying SQL Server Mobile 2005 as a local / single user database across Microsoft Mobile devices including the Tablet PC...(&lt;a href="http://blogs.msdn.com/smartclientdata/archive/2005/07/15/439008.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=439008" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Blogicles/default.aspx">Blogicles</category><category domain="http://blogs.msdn.com/smartclientdata/archive/tags/Occasionally+Connected+Data/default.aspx">Occasionally Connected Data</category></item></channel></rss>