score:1

Accepted answer

below code is working for me.

thanks every one

    var commonrows = from r1 in dt.asenumerable()
                             join r2 in tempdt.asenumerable()
                             //on r1.field<object>(0).tostring() equals r2.field<object>(4).tostring()
                             on r1[0].tostring() equals r2[4].tostring()
                             select r2;
            if (commonrows.any())
            {
                abcdefgh = commonrows.count();
                dt123 = commonrows.copytodatatable();
                // ring the ghanta of gutlu
            }

score:0

field expects the underlying datatype to be a string.

see: http://msdn.microsoft.com/en-us/library/bb301394.aspx

invalidcastexception
the value type of the underlying column could not be cast to the type specified by the generic parameter, t.

you could use object to ignore the type as jens kloster purposed. however, there is something wrong with your design if you don't know the datagtype of your columns.

score:0

this error is caused by a mismatch datatypes between properties' entity and underlying table columns.

score:2

casting to string isn't really possible, since double and string are 2 completely unrelated classes. perhaps try comparing their .tostring() values. or if you want to be completely safe, compare their string formats, so you don't get any nullreferenceexceptions: string.format("{0}", fieldvalue)

score:6

here is where i think your problem is:

from r1 in dt.asenumerable()
join r2 in tempdt.asenumerable() on
r1.field<string>(0)  //<-- this may not be string
equals 
r2.field<string>(4) //<-- this may not be string
select r2;

what you could do is to treat it as object:

from r1 in dt.asenumerable()
join r2 in tempdt.asenumerable() on
(string.empty + r1.field<object>(0)) <-- edited by andreas x
equals 
(string.empty + r2.field<object>(4)) <-- edited by andreas x
select r2;

what you should do, is to make sure your index numbers (0 and 4) points to the same type.

edit: i usually use the old asp-trick to aboid null pointers when asking to the tostring value.


Related Query

More Query from same tag