Bhavesh Jadav

Bhavesh Jadav

  • 945
  • 1.1k
  • 3.8k

Specified cast is not valid. in LINQ query.

Apr 23 2018 1:23 AM
Hello, everyone please help me to solve my error.
 
Specified cast is not valid. in LINQ query. a code is given below
 
  1. try  
  2. {  
  3.     var result = (from tbl1 in dsSearchdata.Tables[1].AsEnumerable()   
  4.                  join tbl2 in dsCategoryProducts.Tables[0].AsEnumerable()   
  5.                  on tbl1.Field<int>("ProductId") equals tbl2.Field<int>("ProductId")   
  6.     select tbl1);
  7.     if (result.Count() > 0)  
  8.     {  
  9.         DataTable dt = new DataTable();  
  10.         dt = result.CopyToDataTable();  
  11.         dsSearchdata.Tables[i].Rows.Clear();  
  12.         dsSearchdata.Tables[i].Merge(dt, true);  
  13.     }  
  14.     else  
  15.     {  
  16.        dsSearchdata.Tables[i].Rows.Clear();  
  17.     }  
  18. }  
  19. catch (Exception ex)  
  20. {  

It generate exeption 'Specified cast is not valid.'
 
Thanks in advance.

Answers (3)