﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Updating BO causes Business layer exception</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Mon, 18 May 2026 08:50:22 GMT</lastBuildDate><ttl>20</ttl><item><title>Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost10961.aspx</link><description>I have created a windows form that maintains a simple table in a SQL Server database.&amp;nbsp; The first column of this table is also the primary key.&lt;/P&gt;&lt;P&gt;I can add new records to the business object (and underlying table) but when I try to update one of the existing records I get the following error.&amp;nbsp; The problem table only was one column as the primary key and it is not an identity column (auto generated).&amp;nbsp; Looking at the partial BO class, it appears that the correct column is being used as the primary key.&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;BusinessLayerException&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;An error occurred while saving an the data to the server.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;DataLayerSavingException&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;DataLayerException&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" color=#000000 size=3&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 size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;Source&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;: MicroFour StrataFrame Business&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" color=#000000 size=3&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 size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;Stack Trace: &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at MicroFour.StrataFrame.Data.DataLayer.BuildUpdateInfo(DataTable UpdatingTable, Boolean Transactional, String TransactionKey)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at MicroFour.StrataFrame.Data.DataLayer.UpdateDataTableThread(Object ThreadParams)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at MicroFour.StrataFrame.Data.DataLayer.SaveByForm(DataTable TableToSave, Boolean Transactional, String TransactionKey)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at MicroFour.StrataFrame.Business.BusinessLayer.SaveByForm(Boolean Transactional, String TransactionKey)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save(Boolean Transactional, String TransactionKey)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save()&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at MicroFour.StrataFrame.UI.Windows.Forms.MaintenanceFormToolStrip.cmdSave_Click(Object sender, EventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32 clicks)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.Control.WndProc(Message&amp;amp; m)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ScrollableControl.WndProc(Message&amp;amp; m)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.ToolStrip.WndProc(Message&amp;amp; m)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.Control.ControlNative&amp;#119;indow.OnMessage(Message&amp;amp; m)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.Control.ControlNative&amp;#119;indow.WndProc(Message&amp;amp; m)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;at System.Windows.Forms.Native&amp;#119;indow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Mon, 27 Aug 2007 08:29:40 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11082.aspx</link><description>No problem, glad you got it working :)</description><pubDate>Mon, 27 Aug 2007 08:29:40 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11066.aspx</link><description>Glad you got it working.   I've had a few problems like that and they are frustrating...and like you, I learned a lot from the posts too!  :D</description><pubDate>Fri, 24 Aug 2007 11:18:01 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11064.aspx</link><description>&lt;BR&gt;Trent, Greg, Ben,&lt;/P&gt;&lt;P&gt;I recreated the form, BO, etc from scratch, and all is well with the world.&amp;nbsp; I have no idea why the first app had the problem with edit/save.&amp;nbsp;Must have been some glitch someplace. &amp;nbsp;Regardless, I learned a lot and thank each of you for your valued input.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Doug</description><pubDate>Fri, 24 Aug 2007 10:43:08 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11060.aspx</link><description>Ben,&lt;/P&gt;&lt;P&gt;Thanks for the explaination.&amp;nbsp; That all makes sense now.&amp;nbsp; I'll let you know how my re-write from scratch goes with the other problem child (edit/save exception).&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Doug</description><pubDate>Fri, 24 Aug 2007 09:55:19 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11058.aspx</link><description>The reason you're getting the InvalidCastException is because SF does not initialize PK fields when you add a new row.&amp;nbsp; When you add a new row, all of the other fields are initialized to default values so they won't be DBNull.Value, however, the PK field(s) is(are) left alone.&amp;nbsp; So, you can either set the ReturnAlternateOnNull option for the pk and return String.Empty (just like you've been doing :)), or you can manually set the pk field to String.Empty in the SetDefaultValues() method (in the main code file of the business object).&amp;nbsp; Either way would work... and then, like you mentioned before, just add either a required field or a custom business rule for the PK, and the user won't be able to enter a blank one into the database (which they would only be able to do once, since the PK has to be unique ;)).</description><pubDate>Fri, 24 Aug 2007 09:42:02 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11050.aspx</link><description>Ben,&lt;/P&gt;&lt;P&gt;At this point, I think I will throw away the "problem child" and try to create the form again from scratch and see if I get the same problem&amp;nbsp;regarding the&amp;nbsp;edit/save issue.&amp;nbsp; I would still like to understand the problem I have when trying to add a new record and getting the casting exception.&lt;/P&gt;&lt;P&gt;Thanks!</description><pubDate>Fri, 24 Aug 2007 09:24:43 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11047.aspx</link><description>Ok, I've created a small app that has the following characteristics&lt;/P&gt;&lt;P&gt;1. Maintains a table that has 3 columns, the first of which is a varchar(10) and is the primary key.&lt;/P&gt;&lt;P&gt;2. The BO for this table has the&amp;nbsp;PK set as required and does not allow null.&lt;/P&gt;&lt;P&gt;3. With this new app, I can edit and save records (of &lt;A href="mailto:course...#@$%$"&gt;course...#@$%$&lt;/A&gt;#@)&lt;/P&gt;&lt;P&gt;4. I am unable to add new records via the form.&amp;nbsp; The instant I click "New" I get the following exception thrown...&lt;/P&gt;&lt;P&gt;"Unable to cast object of type 'System.DBNull' to type 'System.String'."&lt;/P&gt;&lt;P&gt;Again, it acts like it is trying to add the record to the BO before the user can fill in any data via the form. The only way I've found around this exception is to set the BO to return alternate of String.Empty.&amp;nbsp; &lt;/P&gt;&lt;P&gt;??????</description><pubDate>Fri, 24 Aug 2007 09:21:15 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11044.aspx</link><description>I am in the process of creating a small sample app of the problem.&amp;nbsp;&amp;nbsp; I'll keep you posted on how it goes, etc.&lt;/P&gt;&lt;P&gt;Thanks!</description><pubDate>Fri, 24 Aug 2007 08:51:09 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11043.aspx</link><description>OK, do you have a small sample app that reproduces the problem?&amp;nbsp; Say, one form, with your one business object?&amp;nbsp; And just a screen shot of the table in the database so that I can see the structure.&amp;nbsp; I'm just not seeing anything else that you've done wrong, so I'll probably have to step through it.&amp;nbsp; Thanks :)</description><pubDate>Fri, 24 Aug 2007 08:43:18 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11042.aspx</link><description>Greg,&lt;/P&gt;&lt;P&gt;I'm tracking 100% with what you posted.&amp;nbsp; The PK is entered by the user.&amp;nbsp; I have the PK in the BO set as "required" and "does not allow null".&amp;nbsp; I am using the strataframe maintenance form.&amp;nbsp; When I go to add a new record, the exception "Unable to cast object of type 'System.DBNull' to type 'System.String'." is thrown on the PK immediately when I click the "new" button on the form.&amp;nbsp; This is before I can add any data (PK) via the form.&amp;nbsp; The only way to get around this exception (that I've found) is to set the BO to "return alternate on null" with a String.Empty.&amp;nbsp; Doing this allows me to add new records via the form.&amp;nbsp; But... as previously discussed, this is not an ideal way to handle a PK value.&lt;/P&gt;&lt;P&gt;It acts as though it is adding the record to the BO before the user is allowed to enter any data via the form.&lt;/P&gt;&lt;P&gt;Now... when I have an existing record with a PK populated in the form (and the BO obviously), and I click "Edit" and then &lt;U&gt;immediately&lt;/U&gt; click "Save" without ever changing any data, I get the following...&lt;/P&gt;&lt;P&gt;"BusinessLayerException&lt;BR&gt;&amp;nbsp; An error occurred while saving an the data to the server.&lt;BR&gt;DataLayerSavingException&lt;BR&gt;&amp;nbsp; Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.&lt;BR&gt;DataLayerException&lt;BR&gt;&amp;nbsp; Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.&lt;/P&gt;&lt;P&gt;Source&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : MicroFour StrataFrame Business&lt;BR&gt;&lt;/P&gt;&lt;P&gt;I get this regardless of how I have the PK setup.</description><pubDate>Fri, 24 Aug 2007 08:27:37 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11041.aspx</link><description>I wouldn't say terribly wrong...there's just lots of moving pieces and looks like you haven't figure out a couple of them :hehe:&lt;br&gt;
&lt;br&gt;
OK, I'm guessing that error is returned at runtime, not compile time (i.e. it's an exception being thrown, not a compile error).  The problem is likely that you aren't creating your PK and setting the value before you save the BO (or something like that).  In the Event Handlers region of your BO (main file), there is the SetDefaultValues handler. This is an excellent place to set the value of the PK, if it can be set by your app.  E.g.&lt;br&gt;
&lt;br&gt;
[codesnippet]Private Sub SampleBO_SetDefaultValues()&lt;br&gt;
  '-- Set the PK value, in this case using a private method called GetNewSampleNumber (which would&lt;br&gt;
  '    return a new unique sample number).&lt;br&gt;
  Me.SampleNumber = Me.GetNewSampleNumber()&lt;br&gt;
End Sub[/codesnippet]&lt;br&gt;
&lt;br&gt;
If the PK is set by the user, then you'll need to check that it is actually set. The easiest way is to just indicate that the field is required. Open the BO's designer, hit F4 to view the properties and look for the ReqiredFields property.  You can easily set the PK field as required and they won't be able to save without it.&lt;br&gt;
&lt;br&gt;
There is one more step you likely will want to take if the user is providing the PK: check that it is actually unique. There are a couple of ways to do this. The first is to check for a sql duplicate exception when saving...not the best way, but it can work.  The better way (according a recent post about this very thing) is to check if it's unique using the ExecutScalar method. You'd do this in the CheckRulesOnCurrentRow event. E.g.&lt;br&gt;
&lt;br&gt;
[codesnippet]Private Sub MyBo_CheckRulesOnCurrentRow(ByVal e As Microfour.StrataFrame.Business.CheckRulesEventArgs)&lt;br&gt;
  '-- Check that the value provide is unique (if one was provided)&lt;br&gt;
  Dim sampleNumberExists As Boolean&lt;br&gt;
  Using cmd As New SqlCommand()&lt;br&gt;
    cmd.CommandText = "If Exists(Select SampleNumber" _&lt;br&gt;
                                         &amp; " From SampleMaster" _&lt;br&gt;
                                         &amp; " Where SampleNumber = @sampleNumber)" _&lt;br&gt;
                                    &amp; " Begin Select 1 End" _&lt;br&gt;
                                    &amp; " Else" _&lt;br&gt;
                                    &amp; " Begin Select 0 End"&lt;br&gt;
    cmd.Parameters.Add("@sampleNumber",varchar,50)&lt;br&gt;
    cmd.Parameters("@sampleNumber").Value = Me.SampleNumber&lt;br&gt;
    sampleNumberExists = CBool(Me.ExecuteScalar(cmd))&lt;br&gt;
  End Using&lt;br&gt;
&lt;br&gt;
  '-- If the sample exists, add a broken rule&lt;br&gt;
  Me.AddBrokenRule(SampleBOFieldNames.SampleNumber, "The Sample Number indicated is already in use.")&lt;br&gt;
End Sub[/codesnippet]&lt;br&gt;
&lt;br&gt;
Note I just typed in the code, so there might be some syntax/typing errors. Hopefully this helps you understand how to manage the PK.&lt;br&gt;
&lt;br&gt;
Of course, this might have nothing to do with the original problem.</description><pubDate>Thu, 23 Aug 2007 17:33:48 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11040.aspx</link><description>I understand and agree totally about the PK not being null.&amp;nbsp; I had the BO setup that way originally, but when I do, I get the following compile error.&amp;nbsp; (see attached document)&lt;/P&gt;&lt;P&gt;The only way I could get it to work was to change the PK within the BO to "return alternate on null" with String.Empty.&lt;/P&gt;&lt;P&gt;I must be doing something terribly wrong....</description><pubDate>Thu, 23 Aug 2007 16:20:26 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11028.aspx</link><description>The thing that pops out to me is that you are allowing NULLs in your PK (you have set to return an alternate value of an empty string if the db value is NULL).  This may not be causing your problems here, but it has caused me problems in the past.  First, while you can allows NULLs in a PK column, this is a bad idea.  What will happen is that one record will be allowed a NULL value in the PK, then when a second record with a NULL PK added, it will fail.  The record with a Null value can also get "lost" as most search criterion and joins on the PK won't include it.  These can be tough bugs to hunt down (yep, I've done this  :( )&lt;br&gt;
&lt;br&gt;
You need to setup the PK field in the database to be the PK (unique values, clustered likely), then setup the BO such that it doesn't allow nulls at all.  If you are generating the PK automatically, you can set its value in the SetDefaults event (I think that is the event name...it's one of the two events that are in a BO when you create it, in the main file).  If the user is entering the PK, then you will likely need to check that it is unique in the other event in the BO, CheckBusinessRules (again, I think that is what it's called).&lt;br&gt;
&lt;br&gt;
I doubt this is the causing the current problem, but thought I'd point it out.</description><pubDate>Thu, 23 Aug 2007 11:22:37 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11027.aspx</link><description>Ben,&lt;/P&gt;&lt;P&gt;I'm afraid I get true.&amp;nbsp; see attached...&lt;/P&gt;&lt;P&gt;Doug</description><pubDate>Thu, 23 Aug 2007 11:21:49 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11026.aspx</link><description>What do you get in the Watch window when you test&lt;/P&gt;&lt;P&gt;boVariable.IsPrimaryKeyField("SampleNumber")&lt;/P&gt;&lt;P&gt;?&amp;nbsp; It should return true... if it's not, then that's the root of our problem.</description><pubDate>Thu, 23 Aug 2007 10:59:04 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11025.aspx</link><description>Ben,&lt;/P&gt;&lt;P&gt;I've attached a word document with screenshots that hopefully captures what you are wanting to see.&lt;/P&gt;&lt;P&gt;Most of what I see in the local varialbles of the BO looks ok.&amp;nbsp; The exception being the DataSet value which is null.&amp;nbsp; Hopefully this will make sense to you when you see the screenshots.&lt;/P&gt;&lt;P&gt;Thanks for all your help. I know it's something probably very simple that I've done, but I've not been able to find it.&lt;/P&gt;&lt;P&gt;Doug</description><pubDate>Thu, 23 Aug 2007 10:13:49 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11024.aspx</link><description>When you're at that break point in the BeforeSave, check these values in the Watch window and let me know what you get:&lt;/P&gt;&lt;P&gt;boVariable["SampleNumber"]&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;boVariable.CurrentRow["SampleNumber"]&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;boVariable.CurrentDataTable.Columns["SampleNumber"]</description><pubDate>Thu, 23 Aug 2007 09:06:55 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11019.aspx</link><description>Ben, I understand what you are saying.&amp;nbsp; Every where I look, I see the primary key field "SampleNumber" defined correctly, i.e. in the table, in the BO, etc.&lt;BR&gt;I put a breakpoint in the BeforeSave() method of the business object and when I examine the primary key values, it is correct.&amp;nbsp; I will attempt to attach screenshots of various pieces of this "puzzlement".&lt;/P&gt;&lt;P&gt;&lt;BR&gt;SampleBO.designer.cs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static string[] _PrimaryKeyFields = new string[] { "SampleNumber" };&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// Gets the field or fields that comprise the primary key for the business object.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// &amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override string[] PrimaryKeyFields&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&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; return _PrimaryKeyFields;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;/// SampleNumber&lt;BR&gt;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;/// &amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;&lt;BR&gt;&amp;nbsp;[Browsable(false),&lt;BR&gt;&amp;nbsp; BusinessFieldDisplayInEditor(),&lt;BR&gt;&amp;nbsp; Description("SampleNumber"),&lt;BR&gt;&amp;nbsp; DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]&lt;BR&gt;&amp;nbsp;public System.String SampleNumber&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;object loValue;&lt;BR&gt;&amp;nbsp;&amp;nbsp;loValue = this.CurrentRow["SampleNumber"];&lt;BR&gt;&amp;nbsp;&amp;nbsp;if (loValue == DBNull.Value)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return String.Empty;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;else&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (System.String)loValue;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;if (value != String.Empty)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.CurrentRow["SampleNumber"] = value;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;else&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.CurrentRow["SampleNumber"] = DBNull.Value;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// A PropertyDescriptor class used to Get and Set the value of the SampleNumber property.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// &amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private class Field_SampleNumber_Descriptor : MicroFour.StrataFrame.Business.FieldPropertyDescriptor&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Field_SampleNumber_Descriptor() : base("SampleNumber") { }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private System.Type _PropertyType = typeof(System.String);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override object GetValue(Object component)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&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; return ((SampleBO)component).SampleNumber;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void SetValue(Object component, object Value)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&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; ((SampleBO)component).SampleNumber = (System.String)Value;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override System.Type PropertyType&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&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; get&lt;BR&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;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return this._PropertyType;&lt;BR&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;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override System.Type ComponentType&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&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; get&lt;BR&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;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return _ComponentType;&lt;BR&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;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;</description><pubDate>Thu, 23 Aug 2007 08:39:44 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11011.aspx</link><description>Hehe, sorry for the delay, been digging at the pile on my desk :)&amp;nbsp; OK, that error you're getting is because the business object's CurrentDataTable thinks that it does not the DataColumn for the field(s) that are part of the PrimaryKeyFields array.&amp;nbsp; So, if the PrimaryKeyFields array contains "ID1" and "ID2", then the CurrentDataTable of the business object needs to have the columns for ID1 and ID2 (otherwise, the business object won't be able to send the primary key to the server to update the record, because the BO can't find the PK's column within its internal DataTable).&amp;nbsp; What I would do it put a break point on the call to your BO.Save(), and in the Watch window, check the visualizer for the BO.CurrentDataTable property (by clicking on the little magnifying glass, you'll get a window with a grid that shows the contents of the table).&amp;nbsp; Make sure that the table actually contains the column that is your primary key.</description><pubDate>Wed, 22 Aug 2007 14:50:58 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11009.aspx</link><description>Thanks Greg.&amp;nbsp; It makes sense that it's some generated code someplace that is somehow confused about the primary key attributes of the table.&amp;nbsp; I'm sure it's something simple that I've done, but after several days trying to find it, I decided to turn to the experts.&amp;nbsp; Ben, any help you could provide would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Doug</description><pubDate>Wed, 22 Aug 2007 14:41:00 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost11002.aspx</link><description>Well, I think Ben will likely have to help you. It doesn't appear to be a SQL problem. I'm guessing the exception occurs when the data source item is attempting to create the SQL for the update, but I don't know enough about the internals to have any idea why it would fail (especially since it works when you add new fields).</description><pubDate>Wed, 22 Aug 2007 13:44:37 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost10999.aspx</link><description>Greg,&lt;/P&gt;&lt;P&gt;Thanks for the explaination.&amp;nbsp; I modified the code to log the sql commands as follows&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;MicroFour.StrataFrame.Data.&lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;DataBasics&lt;/FONT&gt;&lt;FONT size=2&gt;.DataSources[&lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;""&lt;/FONT&gt;&lt;FONT size=2&gt;].SetDebugOn(&lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;"c:\\MyDebug.html"&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;true&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;And here is what the MyDebug.html file contains after getting the exception - BusinessLayerException&lt;BR&gt;&amp;nbsp; An error occurred while saving an the data to the server.&lt;BR&gt;DataLayerSavingException&lt;BR&gt;&amp;nbsp; Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;&lt;TABLE cellSpacing=0&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Command #: &lt;/TD&gt;&lt;TD&gt;1 &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Timestamp: &lt;/TD&gt;&lt;TD&gt;2007-08-22 11:45:03.641 &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=TitleSpacer colSpan=2&gt;General Command Settings &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Command Type: &lt;/TD&gt;&lt;TD&gt;Text &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Object Type: &lt;/TD&gt;&lt;TD&gt;System.Data.SqlClient.SqlCommand &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Connection String: &lt;/TD&gt;&lt;TD&gt;Data Source=IST022246\SQLEXPRESS;Initial Catalog=FitWearDatabase;Integrated Security=True;Persist Security Info=False;Asynchronous Processing=True &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Transaction: &lt;/TD&gt;&lt;TD&gt;False &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=Title colSpan=2&gt;Command Settings &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;CommandText: &lt;/TD&gt;&lt;TD&gt;Select * from SampleMaster &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=Title colSpan=2&gt;Command Parameters &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;N/A &lt;/TD&gt;&lt;TD&gt;No parameters are defined &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE cellSpacing=0&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Command #: &lt;/TD&gt;&lt;TD&gt;2 &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Timestamp: &lt;/TD&gt;&lt;TD&gt;2007-08-22 11:45:03.922 &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=TitleSpacer colSpan=2&gt;General Command Settings &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Command Type: &lt;/TD&gt;&lt;TD&gt;Text &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Object Type: &lt;/TD&gt;&lt;TD&gt;System.Data.SqlClient.SqlCommand &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Connection String: &lt;/TD&gt;&lt;TD&gt;Data Source=IST022246\SQLEXPRESS;Initial Catalog=FitWearDatabase;Integrated Security=True;Persist Security Info=False;Asynchronous Processing=True &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;Transaction: &lt;/TD&gt;&lt;TD&gt;False &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=Title colSpan=2&gt;Command Settings &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;CommandText: &lt;/TD&gt;&lt;TD&gt;select * from SampleMaster &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=Title colSpan=2&gt;Command Parameters &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class=RowHeader&gt;N/A &lt;/TD&gt;&lt;TD&gt;No parameters are defined &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;The table in question has only the first column defined as the primary key, and the Business Object partial code has the correct column as the primary key.&amp;nbsp; (non auto-incremeting, and defined as such in the BO) I can add new records but when I try to edit/save a record (via a strataframe maintenance form) I get the above expection.&lt;/P&gt;&lt;P&gt;Thanks for the help!</description><pubDate>Wed, 22 Aug 2007 11:47:16 GMT</pubDate><dc:creator>Doug Birtell</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost10993.aspx</link><description>Oh, and as to your confusion about SetDebugOn, this is a method of a DataSource, not the DataSources collection.  The code is DataSources(""), which is using the default property of the DataSources class (the indexer in C#), which is referencing one of the DataSource items in the collection by it's key (in this case an empty string).</description><pubDate>Wed, 22 Aug 2007 10:16:54 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Updating BO causes Business layer exception</title><link>http://forum.strataframe.net/FindPost10992.aspx</link><description>Doug,&lt;br&gt;
&lt;br&gt;
This statement simply exports all the sql that is generated by the indicated datasource to the indicated file, in html format.  I.e.&lt;br&gt;
&lt;br&gt;
[codesnippet]MicroFour.StrataFrame.Data.Databasics.DataSources("").SetDebugOn("c:\MyDebug.html",True)[/codesnippet]&lt;br&gt;
&lt;br&gt;
will write all the sql statements generated by the default data source, with the key of an empty string (DataSources("")) to the "c:\MyDebug.html" file.  Typically you set this in the SetDataSources (pretty sure that is its name) method in AppMain.  However, you can actually put it anywhere in code after the datasources are set.  &lt;br&gt;
&lt;br&gt;
When you open this file, you'll see every sql command sent (after debugging has been turned on).  This way you can see if the commands being sent to the database are OK.  It can really narrow down were to start looking for the problem.&lt;br&gt;
&lt;br&gt;
Hope this helps!</description><pubDate>Wed, 22 Aug 2007 10:12:30 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>