I have a List
I have a DB table with the same 3 fields. I need to compare PieceID to make sure the are the same using LINQ. How do I get the table into a List or something so I can use it. I tried datareader and datatable and it does not seem to be able to use them.
I know that I have to use a Join, but I cannot even start to figure out the query until I can use the DB fields.
Please help.
Thanks for your help ahead of time.
Arep
A RepaskyPosted Mar 7, 2012, 1:54 PM
VulpesPosted Mar 7, 2012, 12:56 PM
A RepaskyPosted Mar 7, 2012, 12:04 PM
VulpesPosted Mar 7, 2012, 12:03 PM
A RepaskyPosted Mar 7, 2012, 11:53 AM
VulpesPosted Mar 7, 2012, 11:23 AM
So, we know that this works:
var query = from list in fileList
join DataRow db in dt.Rows
on list.ClaimNbr equals db["ClaimNbr"].ToString()
select (int)db["PieceID"];
but this doesn't work:
var query = from list in fileList
join DataRow db in dt.Rows
on new { list.ClaimNbr, list.JobNumber }
equals new { DbClaimNbr = db["ClaimNbr"].ToString(), DbJobNumber = db["JobNumber"].ToString() }
where list.PieceID != db["PieceID"].ToString("D6")
select new { ClaimNbr = list.ClaimNbr, ListPieceID = list.PieceID, DbPieceID = db["PieceID"].ToString("D6") };
So that tells us that:
1. It can't be anything to do with the first two lines as they're the same in both cases.
2. list.ClaimNbr is definitely a string otherwise it could never be equal to db["ClaimNbr"].ToString().
The only remaining possibility is that list.JobNumber is not a string. Could it be an int, perhaps ?
A RepaskyPosted Mar 7, 2012, 9:51 AM
I see what you are talking about that PieceID would never compare. I also see what you mean about the types. So I copied your code over into the program. It gets the same type error.
Arep
VulpesPosted Mar 6, 2012, 6:29 PM
A RepaskyPosted Mar 6, 2012, 5:59 PM
A RepaskyPosted Mar 6, 2012, 5:23 PM
on list.ClaimNbr equals db["ClaimNbr"].ToString()
So I have to figure out how to do that. I will start looking online.
How can I do that?
A RepaskyPosted Mar 6, 2012, 4:55 PM
I got interrupted and just got back to this. I was doing some testing after you helped me get this code to compile. The PieceID in the file (list) and that on the DB are the same, but I get my error message on every ClaimNbr. I should never get this message.
PieceID does not match for ClaimNbr 00013E9908104 where the file has 000001 and the database has 1
It is like it is doing the opposite that it is supposed to.
So here is the code.
A RepaskyPosted Mar 5, 2012, 11:45 AM
where list.PieceID != (int)db["PieceID"]
to
where list.PieceID != db["PieceID"].ToString()
And I changed the write to console.writeline.
Thanks,
Arep
VulpesPosted Mar 5, 2012, 11:30 AM
A RepaskyPosted Mar 5, 2012, 10:37 AM
A RepaskyPosted Mar 5, 2012, 10:11 AM
Arep
VulpesPosted Mar 5, 2012, 5:14 AM
A RepaskyPosted Mar 4, 2012, 10:08 PM
VulpesPosted Mar 4, 2012, 5:50 PM
A RepaskyPosted Mar 4, 2012, 5:44 PM
VulpesPosted Mar 4, 2012, 5:22 PM
A RepaskyPosted Mar 4, 2012, 5:07 PM
I get the error:
Error 1 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
VulpesPosted Mar 3, 2012, 3:56 PM