﻿<?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?)  » Varchar Primary Keys, System.DBNull errors, and all that</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Mon, 08 Jun 2026 20:27:30 GMT</lastBuildDate><ttl>20</ttl><item><title>Varchar Primary Keys, System.DBNull errors, and all that</title><link>http://forum.strataframe.net/FindPost3766.aspx</link><description>As I am still new to the framework, I am making myself cheat sheets on how to do various things once I've figured it out the first time.&lt;/P&gt;&lt;P&gt;I wanted to post this here for two reasons: 1) in case someone might find it useful, and 2) to see if I am missing something, or, worse, doing extra work I don't have to be doing. :)&lt;/P&gt;&lt;P&gt;So recently I defined a varchar field as PK for a table and spent a little while staring at the 'cannot convert System.DBNull to the Text property of...' error trying to figure out what to do. This is what I came up with.&lt;/P&gt;&lt;P&gt;Note that the last three bullet points are the only additional work on top of what you would normally do. It's just very confusing at first knowing what to change and where.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Design table as normal in DDT, with the varchar primary key&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Don't worry about specifying a default value for the PK here&lt;/LI&gt;&lt;LI&gt;The DDT default value only applies at the database level, which is not where the problems arise&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;Create the BO in your project&lt;/LI&gt;&lt;LI&gt;Map the BO in the mapper as you normally would&lt;/LI&gt;&lt;LI&gt;Add the data retrieval methods to the BO as you normally would (FillAll(), etc.)&lt;/LI&gt;&lt;LI&gt;Add a new method where you turn PK auto-incrementing off&lt;/LI&gt;&lt;/UL&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT size=2&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;FONT size=2&gt; ConstructorCommon()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.PrimaryKeyIsAutoIncremented = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;false&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;UL dir=ltr&gt;&lt;LI&gt;Call this new method from each constructor&lt;/LI&gt;&lt;LI&gt;In the BO's SetDefaultValues method, give the PK a default non-null value.&lt;/LI&gt;&lt;/UL&gt;&lt;FONT size=2&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;FONT size=2&gt; WizardInstructionsBO_SetDefaultValues()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.PageDescription = &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;"DefaultPageDescriptionKey"&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;That's it! I used this BO on a maintenance form and everything is working as it should.&lt;/FONT&gt;</description><pubDate>Mon, 23 Oct 2006 08:24:48 GMT</pubDate><dc:creator>Chris Crabtree</dc:creator></item><item><title>RE: Varchar Primary Keys, System.DBNull errors, and all that</title><link>http://forum.strataframe.net/FindPost3787.aspx</link><description>No problem :)</description><pubDate>Mon, 23 Oct 2006 08:24:48 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Varchar Primary Keys, System.DBNull errors, and all that</title><link>http://forum.strataframe.net/FindPost3785.aspx</link><description>Your other reply set me straight. Replace the two steps above starting with "Add a new method..." with the following single step:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT size=2&gt;&lt;P&gt;In the BO designer, set the PrimaryKeyIsAutoIncremented property to False.&lt;/P&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;FONT size=2&gt;&lt;P&gt;Much easier! Thanks, Trent!&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Mon, 23 Oct 2006 08:05:00 GMT</pubDate><dc:creator>Chris Crabtree</dc:creator></item><item><title>RE: Varchar Primary Keys, System.DBNull errors, and all that</title><link>http://forum.strataframe.net/FindPost3774.aspx</link><description>Chris,&lt;/P&gt;&lt;P&gt;As I mentioned on your other post, if you are going to be using VarChar primary keys I would create a subclassed BusinessLayer that already has the PrimaryKeyIsAutoincremented properyt set to false.&amp;nbsp; All you need to do is create a class that looks something like this:&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;MyCustomBusinessLayer&lt;/FONT&gt;&lt;FONT size=2&gt; : MicroFour.StrataFrame.Business.&lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;BusinessLayer&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/FONT&gt;&lt;FONT size=2&gt; MyCustomBusinessLayer()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/FONT&gt;&lt;FONT size=2&gt;.InitializeComponent();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;FONT size=2&gt; InitializeComponent()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/FONT&gt;&lt;FONT size=2&gt;.PrimaryKeyIsAutoIncremented = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;false&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Once you have a custom business layer class created, you would then change any new business objects inherited class:&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;public&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;BusinessObject1&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; : MyCustomNamespace.&lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;MyCustomBusinessLayer&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#008080 size=2&gt;&lt;FONT color=#1f5080&gt;This way you do not have to recreate that code you had posted every time and it will respect the PrimaryKeyIsAutoIncremented property through the inherited class.&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Sun, 22 Oct 2006 11:44:51 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>