﻿<?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 » WinForms (How do I?)  » Maintenenanced Form- Add buttom giving InvalidCastException</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 07:01:42 GMT</lastBuildDate><ttl>20</ttl><item><title>Maintenenanced Form- Add buttom giving InvalidCastException</title><link>http://forum.strataframe.net/FindPost23724.aspx</link><description>I have a standard maintenance form, and am able to browse through the records no problem. However, when I try to add a record , I get an Invalid Cate Exception in code below. I have changed some fields recently on the database, but my Primary Key is SMA_PK which is set up as an INT field in the table.. this is what seems to be causing the error. I suspect I have not changed something somewhere ....&lt;/P&gt;&lt;P&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;///&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;///&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt; SMA_PK&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;///&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;/summary&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;[Browsable(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;false&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;),&lt;/P&gt;&lt;P&gt;BusinessFieldDisplayInEditor(),&lt;/P&gt;&lt;P&gt;Description(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"SMA_PK"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;),&lt;/P&gt;&lt;P&gt;DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; System.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Int32&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SMA_PK&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;get&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;return&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; (System.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Int32&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.CurrentRow[&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"SMA_PK"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;];&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;set&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.CurrentRow[&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"SMA_PK"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;] = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;value&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Wed, 01 Jul 2009 13:37:02 GMT</pubDate><dc:creator>Ger Cannoll</dc:creator></item><item><title>RE: Maintenenanced Form- Add buttom giving InvalidCastException</title><link>http://forum.strataframe.net/FindPost23733.aspx</link><description>It sounds like you have turned off the auto-initialize option on the BO to pre-initialize the values.  Or your are using a user def-ined PK and have the PrimaryKeyAutoIncremented property set to False and are not providing a PK in the SetDefaultvalues event of the BO.</description><pubDate>Wed, 01 Jul 2009 13:37:02 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Maintenenanced Form- Add buttom giving InvalidCastException</title><link>http://forum.strataframe.net/FindPost23727.aspx</link><description>Hi Trent. &lt;/P&gt;&lt;P&gt;In the Database Table, the Field SMA_PK is set up as Int&lt;/P&gt;&lt;P&gt;Also, as the error is only happening when I try to 'Add',the question of whether it is Null should not arise ?&amp;nbsp;</description><pubDate>Wed, 01 Jul 2009 12:28:34 GMT</pubDate><dc:creator>Ger Cannoll</dc:creator></item><item><title>RE: Maintenenanced Form- Add buttom giving InvalidCastException</title><link>http://forum.strataframe.net/FindPost23725.aspx</link><description>What is SMA_PK typed as within the DataTable?  You are trying to cast it as an Int but it is either Null or a data type other than integer.</description><pubDate>Wed, 01 Jul 2009 11:37:07 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>