Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1
    Utente di HTML.it L'avatar di Sonikag
    Registrato dal
    Mar 2004
    Messaggi
    2,080

    Specified cast is not valid

    Cosa vuol dire questo errore?

    codice:
    Specified cast is not valid. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.InvalidCastException: Specified cast is not valid.
    
    Source Error: 
    
    Line 66: 
    Line 67: 			RepEventi.DataSource = pagedData; 
    Line 68: 			RepEventi.DataBind(); 
    Line 69: 
    Line 70: 			conn.Close();
    L'errore mi viene restituito quando cerco di caricare un repeater. Credevo fosse un problema di dati, quindi ho copiato la stringa sql e l'ho incollata in access, ma tutto funzionava. Non dovrebbe essere un problema di codice in quanto prima funzionava.

    Sonia

  2. #2
    Utente di HTML.it L'avatar di Franz78
    Registrato dal
    Sep 2004
    Messaggi
    730
    pagedData ? cos'è?
    posta il codice sopra...cosi è dura capire...

  3. #3
    Utente di HTML.it L'avatar di Sonikag
    Registrato dal
    Mar 2004
    Messaggi
    2,080
    Si è misteriosamente risolto tutto, a quanto pare ad impallare tutto era un campo null.

    Sonia

  4. #4
    Utente di HTML.it L'avatar di Franz78
    Registrato dal
    Sep 2004
    Messaggi
    730
    ti ci stai facendo male con sti campi null
    meglio per te
    ciao

  5. #5
    Utente di HTML.it L'avatar di Sonikag
    Registrato dal
    Mar 2004
    Messaggi
    2,080
    Si! hai ragione... infatti ci sono ricaduta!
    Sfrutto questo 3d visto che l'errore che mi viene restituito è lo stesso, la causa non so...

    ho questa label:
    codice:
    <asp:Label id="Label1" runat="server"><%#StrTesto2((string)DataBinder.Eval(Container.DataItem, "Giorno"))%></asp:Label>
    La funzione StrTesto2 è questa:

    codice:
    protected string StrTesto2(string testo) 
    		{ 
    			if (testo =="") 
    				return ""; 
    			else 
    			{
    				string pippo = testo + "/";
    				return pippo; 
    			}
    						
    		}
    Vorrei quindi che: Se giorno è null mettesse uno spazio, se non è null mettesse il numero e uno slash.

    Errore:
    codice:
    Specified cast is not valid. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.InvalidCastException: Specified cast is not valid.
    
    Source Error: 
    
    
    Line 84:<TD class="cella1">
    Line 85:<asp:Label id="Label1" runat="server">
    Line 86:<%#StrTesto2((string)DataBinder.Eval(Container.DataItem, "Giorno"))%>
    Line 87:</asp:Label>
    Line 88:
    Sonia

  6. #6
    (DataBinder.Eval(Container.DataItem, "Giorno")).ToString()
    If you want a picture of the future, imagine a boot stamping on a human face-for ever.

  7. #7
    Utente di HTML.it L'avatar di Sonikag
    Registrato dal
    Mar 2004
    Messaggi
    2,080
    dici così?
    codice:
    <%#StrTesto2 (DataBinder.Eval(Container.DataItem, "Giorno")).ToString()%>

  8. #8
    si, la funzione DataBinder.Eval(...) restituisce un Object, una string è un tipo primitivo.
    visto che tutti gli oggetti derivano da Object ed hanno la funzione ToString() qundo vuoi ottenere una stringa non devi castare ma usare questo metodo...
    If you want a picture of the future, imagine a boot stamping on a human face-for ever.

  9. #9
    Utente di HTML.it L'avatar di Sonikag
    Registrato dal
    Mar 2004
    Messaggi
    2,080
    In quel modo mi da un errore di compilazione:
    codice:
    Compilation Error 
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
    
    Compiler Error Message: CS1502: The best overloaded method match for 'giblors.eventi.StrTesto2(string)' has some invalid arguments
    
    Source Error:
    
     
    
    Line 84:<TD class="cella1">
    Line 85:<asp:Label id="Label1" runat="server">
    Line 86:<%#StrTesto2 (DataBinder.Eval(Container.DataItem, "Giorno")).ToString()%>
    Line 87:</asp:Label>
    Line 88:</TD>
    Sonia

  10. #10
    ehm,
    mancano due parentesi...

    StrTesto2 ( (DataBinder.Eval(Container.DataItem, "Giorno")).ToString())
    If you want a picture of the future, imagine a boot stamping on a human face-for ever.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.