StrataFrame Forum

Maintenenanced Form- Add buttom giving InvalidCastException

http://forum.strataframe.net/Topic23724.aspx

By Ger Cannoll - 7/1/2009

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 ....

/// <summary>

/// SMA_PK

/// </summary>

[Browsable(false),

BusinessFieldDisplayInEditor(),

Description("SMA_PK"),

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public System.Int32 SMA_PK

{

get

{

return (System.Int32)this.CurrentRow["SMA_PK"];

}

set

{

this.CurrentRow["SMA_PK"] = value;

}

}

By Trent L. Taylor - 7/1/2009

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.
By Ger Cannoll - 7/1/2009

Hi Trent.

In the Database Table, the Field SMA_PK is set up as Int

Also, as the error is only happening when I try to 'Add',the question of whether it is Null should not arise ? 

By Trent L. Taylor - 7/1/2009

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.