Results 1 to 2 of 2

Thread: Some Type Conversion Errors+Sourabh Das

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    220

    Some Type Conversion Errors+Sourabh Das

    Hi,
    I am getting some unusual simple errors.
    Not good in C#. Please Specify the corrections.
    Regards,

    Code:
    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?)


    Code:
    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.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Some Type Conversion Errors+Sourabh Das

    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width