StrataFrame Forum

InvalidCastException... arggggggg

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

By Ulrik Mueller - 6/22/2009

I'm getting total crazy now.  In my standard application framework I have made several Maintenance Dialogs - but suddenly on a new dialog I'm getting InvalidCastException on everything.....  It states the it is "Unable to cast of type 'System.DBNull' to type 'System.String'" on my primary key field.

The destination table and it happens everytime I click the NEW buttom!!!!!

What the he.. is going on...  Am I missing a flag or.....

Hope that some of you can come up with a way to get me back on track!

Regards
Ulrik

By Trent L. Taylor - 6/23/2009

Well, how do you have your primary key setup? It sounds like you have the PrimaryKeyIsAutoIncrementing property set to false and then are not providing a PK in the SetDefaultValues.
By Ulrik Mueller - 6/23/2009

It is correct that the PrimaryKeyIsAutoincremented is set to FALSE - but I am setting the primary key field in the SETDEFAULTVALUE.

The PK field is a VarChar(5) - in other tables i'm using VC(10) in the same manner!!!

In the SetDefaultValues on the BO i'm making a >> this.pr_id = "ABC"; <<

I tried to run the application on a computer without VS2008 installed - it seems to work better - no crash at least!

By Ulrik Mueller - 6/23/2009

Why why why ...

After I went to the BOM and changed the Field Properties on the PK field it seems to work without any exception.

I changed th "NULL Value Option" to "Return Alternate on Null" and let it set nospace "" in the replacement value!

I just don't know why I have this kind of problems with this specific BO!

/ULRIK

By Ulrik Mueller - 6/23/2009

OK Trent, now I know what the problem is!

Normally everything is working, but when I add the BusinessBindingSource component to my winform and binds it the forms primary BO, it crashes with the InvalidCastException error.

Do you have any ideas on why this is happening ??

If I delete the BBS it is working like a dream!  The reason that I'm using this is because I need to include a DevExpress editbox for currency/numeric data entry!!

Regards
Ulrik

By Trent L. Taylor - 6/24/2009

The only thing I can suggest at this point is for you to provide a sample reproducing the error. There is something else within your code and I would like to see where the point of failure is. Thanks.
By Ulrik Mueller - 6/28/2009

It is working when there are data in the table.
If the table is empty, I get the casting error when the BusinessBindingSource is on the WinForm.
Amy ideas on how to suppres this error during creation of the firste record in a table????

/Ulrik

By Trent L. Taylor - 6/28/2009

Ulrik,

You are trying to do some very basic stuff, so as I mentioned in my previous post, it would help if I could see a sample so I know what you are doing.  An invalid cast exception can from from a lot of places.  The grid can play a role in this since you are binding...so my guess is that you have some logic somewhere within the grid or other event that is causing the issue.  Without seeing a reproduction it is going to be hard to give you any straight answers.