Error: 'Cannot implicitly convert type 'object' to 'decimal'. An explicit conversion exists'

nedash
 
on Sep 20, 2016 07:16 AM
5313 Views

hi

I used session to save data from data base on it below are codes:

Server Error in '/' Application.


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

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

Source Error:

 
Line 571:        DataTable dtFiles = GetFilmInfo(id);
Line 572:        string ImageName = dtFiles.Rows[0][22].ToString();
Line 573:        decimal SeP1 = dtFiles.Rows[0][24];
Line 574:        decimal SeP2 = dtFiles.Rows[0][28];
Line 575:        decimal SeP3 = dtFiles.Rows[0][32];

 

what should I do?

Best regards

Neda

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Sep 20, 2016 07:19 AM
nedash says:
Line 573:        decimal SeP1 = dtFiles.Rows[0][24];
Line 574:        decimal SeP2 = dtFiles.Rows[0][28];
Line 575:        decimal SeP3 = dtFiles.Rows[0][32];

 Replace the above with the below code.

decimal SeP1 = Convert.ToDecimal(dtFiles.Rows[0][24]);
decimal SeP2 = Convert.ToDecimal(dtFiles.Rows[0][28]);
decimal SeP3 = Convert.ToDecimal(dtFiles.Rows[0][32]);