Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Specified Cast is not valid
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Specified Cast is not valid
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01575896
Message ID:
01575896
Vues:
42
Hi everybody,

I am getting 'Specified Cast is not valid' exception on this code
 foreach (DataRow row in dataTable.Rows)
         {
            String addressType;
            Int16 addr_type = row.Field<Int16>("addr_type"); // this line produces this error
I verified that the addr_type column is defined as tinyint not null in the table in SQL Server. I tried other variations as well using Int16? and Int32 and all of them resulted in the same error.

I can try switching to Convert.ToInt16(row["addr_type"]) instead but I've used this code before and it always worked.

BTW, that change did work fine.

Do you see what may be the problem here?
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform