Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Specified Cast is not valid
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Specified Cast is not valid
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01575896
Message ID:
01575896
Views:
45
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
Next
Reply
Map
View

Click here to load this message in the networking platform