Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Specified cast is not valid
Message
 
 
To
01/06/2010 11:44:59
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01466885
Message ID:
01466890
Views:
38
Try getting a Value and also compare it first with DbNull.Value

>I'm trying to add a Beneficiary to an Insurance Policy using an mmGridView. I've done this type of thing before without this error, so I'm pretty sure it's something silly I'm missing.
>
>The line of code that is crashing is this:
>
>
Guid newPK = (Guid)dsBeneficiary.Tables[0].Rows[dsBeneficiary.Tables[0].Rows.Count - 1]["BeneficiaryPK"];
>
>just prior to this line I do a:
>
>
this.oBeneficiary.NewRow(dsBeneficiary, this.oBeneficiary.TableName);
>
>My Beneficiary .cs sets a default BeneficiaryPK using:
>
>
entity.BeneficiaryPK = Guid.NewGuid();
>
>The Watch window shows {} as the value for dsBeneficiary.Tables[0].Rows[dsBeneficiary.Tables[0].Rows.Count - 1]["BeneficiaryPK"].
>
>The full error is this:
>
>
System.InvalidCastException was unhandled by user code
>  Message="Specified cast is not valid."
>  Source="SamaanSystems.IAS.Web"
>  StackTrace:
>       at SamaanSystems.IAS.Web.PolicyEdit.btnAddBeneficiary_Click(Object sender, EventArgs e) in C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Web\PolicyEdit.aspx.cs:line 592
>       at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
>       at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
>       at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
>       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
>       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
>       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>  InnerException:
>
>Any ideas what I have done wrong?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform