Maintenenanced Form- Add buttom giving InvalidCastException


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
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;

}

}


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
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 ? 

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search