Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
var result = (from x in dc.PROC_getAppointmentRules() select x).ToList<PROC_getAppointmentRulesResult>();
                return result;


although DB Column is of type Varchar
While executing loop i am getin the exception "System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.String'."
Posted
Comments
Karthik_Mahalingam 26-Jan-14 8:33am    
the property types are not matching..

You need to look at two things:
1) What dc.PROC_getAppointmentRules actually returns.
And
2) What PROC_getAppointmentRulesResult is compared with the return type you declared your method as having.

But why are you doing that at all?
C#
from x in dc.PROC_getAppointmentRules() select x
is the same as calling dc.PROC_getAppointmentRules and casting the result as an IEnumerable. Which it has to be already in order to use it as a Linq source...so what use is this code?
 
Share this answer
 
"System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.String'."
error is mostly given when you have done a type cast error


for example:

string a=Convert.tostring(12);


check your return type because i feel it is returnin an int64 data type and you are trying to save it in a String datatype
 
Share this answer
 
Comments
Ron Beyer 26-Jan-14 9:06am    
Convert.ToString(12) is a valid and workable piece of code that doesn't throw an exception.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900