Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Specified cast is not valid
Message
De
25/04/2016 08:36:51
 
 
À
23/04/2016 05:17:29
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01635259
Message ID:
01635356
Vues:
48
>>Hi,
>>
>>I've inherited an ASP.NET application which makes use of DataSets and TableAdapters for displaying/editing data.
>>
>>I've added in 2 new columns to a table, with all the vales in these columns being null. I've adjusted the DataTable and TableAdpaters accordingly.
>>
>>Now when I try to access a web page which uses this table, but does not display either of these new fields, I get this error:
>>
>>
Exception Details: System.InvalidCastException: Specified cast is not valid.
>>
>>Source Error: 
>>
>>
>>Line 11323:                get {
>>Line 11324:                    try {
>>Line 11325:                        return ((decimal)(this[this.tablePNRs.ChargeColumn]));
>>Line 11326:                    }
>>Line 11327:                    catch (global::System.InvalidCastException e) {
>>
>>Source File: D:\Development\VS2010\RESREPRICER_asp4\RESREPRICERDataSet.Designer.cs    Line: 11325 
>>
>>Stack Trace: 
>>
>>
>>[InvalidCastException: Specified cast is not valid.]
>>   RESREPRICER.Web.PNRsRow.get_Charge() in D:\Development\VS2010\RESREPRICER_asp4\RESREPRICERDataSet.Designer.cs:11325
>>
>>[StrongTypingException: The value for column 'Charge' in table 'PNRs' is DBNull.]
>>   RESREPRICER.Web.PNRsRow.get_Charge() in D:\Development\VS2010\RESREPRICER_asp4\RESREPRICERDataSet.Designer.cs:11328
>>   RESREPRICER.Web.PrepareInvoicesEdit.butCreate_Click(Object sender, EventArgs e) in D:\Development\VS2010\RESREPRICER_asp4\PrepareInvoicesEdit.aspx.cs:217
>>   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628614
>>   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
>>   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
>>   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
>>   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
>>   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
>>
>>What do I need to do to fix this?
>>
>>This will also lead me on to other issues with passing in nulls to the insert an dupdate of this data, but I'll leave that alone until I understand what's going on here.
>
>In the designer select the 'Charge' column and 'Properties'. Make sure AllowDBNull is True. Check the NullValue - the default is ' Throw Exeception' (which is what you are seeing). Change this to either 'Null' or 'Empty' depending on your requirements. 'Null' will convert DBNull to C# null ; 'Empty' will convert to the default empty value (0 for decimal).

Thanks Viv, that looks like it would have worked. I worked around it by creating a completely separate TableAdapter for the new columns so I can't verify it at the moment but I'm pretty sure that your suggestion would have worked.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform