Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Specified cast is not valid
Message
 
 
À
01/06/2010 11:44:59
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01466885
Message ID:
01466890
Vues:
40
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform