PDA

Click to See Complete Forum and Search --> : Some Type Conversion Errors+Sourabh Das


sd1978
Oct 29th, 2007, 03:51 AM
Hi,
I am getting some unusual simple errors.
Not good in C#. Please Specify the corrections.
Regards,

DateTime CAP_DATE = dsSet.Tables["VW_ASSETLIST2"].Rows[i]["CAP_DATE"];

Error: Cannot implicitly convert type 'object' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)


double CAP_AMT = dsSet.Tables["VW_ASSETLIST2"].Rows[i]["CAP_AMT"];

Error: Cannot implicitly convert type 'object' to 'double'. An explicit conversion exists (are you missing a cast?)

Regards.

Negative0
Oct 29th, 2007, 10:40 AM
The error message is telling you the exact problem.

dsSet.Tables["VW_ASSETLIST2"].Rows[i]["CAP_AMT"] returns an object type and you are trying to convert it implicitly to a double. You need to explicitly do the conversion, by either casting it or using the Parse method to convert the data. This error message is a result of C# being a strongly typed language. In VB.Net you could get away with this if you have Option Strict Off (which I rarely recommend).