Why is the IEnumerable behaving strangely
I have a code as below:
开发者_运维百科var userTest =
from u in userUpdated
select (u.Field<string>("Emp Birthdate"));
var userTest1 =
from u in original
select (u.Field<string>("Date of Birth"));
Value of both the fields are same, i.e. EmpBirthdate and Date of Birth, its as "05 March 1985".
I gave an comparer using the code as:
IEnumerable<DataRow> records =
from u in updateRecords
join o in OriginalRecords
on u.Field<string>("Employee ID")
equals o.Field<int>(" Employee Identity No").ToString()
where (u.Field<string>("Date of Birth") !=
o.Field<string>("Emp Birthdate"))
It does not match, the above records.count() is not equal to 0.
What is the problem?
Thanks in advance
What are you querying with this syntax?
It is generally considered bad practice to use strings like this. A strongly typed adapter would be better and would allow you to access u.EmployeeId
instead of u.Field<string>("Employee ID")
. My guess is that this practice is the cause of your problem. Perhaps you are typing a field name incorrectly. I can't think of any situation where a field name would begin with a space as in " Employee Identity No"
. I actually can't think of a situation where spaces are used at all.
However, without more information, nobody will be able to help you. We need to know what you are querying, what the schema looks like, and why your syntax looks like this. The best answer you will get without providing that is that the most likely cause of your problem is a malformed magic string.
精彩评论