InvalidCastException... arggggggg


Author
Message
Ulrik Mueller
Ulrik Mueller
StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)
Group: Forum Members
Posts: 18, Visits: 59
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

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
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.
Ulrik Mueller
Ulrik Mueller
StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)
Group: Forum Members
Posts: 18, Visits: 59
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!

Ulrik Mueller
Ulrik Mueller
StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)
Group: Forum Members
Posts: 18, Visits: 59
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

Ulrik Mueller
Ulrik Mueller
StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)
Group: Forum Members
Posts: 18, Visits: 59
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

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
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.
Ulrik Mueller
Ulrik Mueller
StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)
Group: Forum Members
Posts: 18, Visits: 59
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

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

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