I’m after some help with some Visual Studio C# code.
I have a data table with some rows & data like below:
Id CodeNum LineNum
1023503 4001 1
1023504 4001 1
1023505 4001 1
1023506 4002 1
1023507 4002 1
1023508 4002 1
1023509 4002 1
1023510 4003 2
1023511 4003 2
1023512 4003 2
1023513 4003 2
1023514 4004 2
1023515 4004 2
1023516 4005 3
1023517 4005 3
1023518 4006 3
1023519 4006 3
1023520 4006 3
1023521 4007 4
1023522 4007 4
1023523 4008 4
1023524 4009 5
1023525 4009 5
1023526 4009 6 x
1023527 4010 6
1023528 4011 6
I need to write a method to do an error check on all the table rows and ensure that any CodeNum only have one LineNum assigned to it.
eg rows with CodeNum 4002 has only LineNum 1 assigned to it, & say rows with CodeNum 4005 has only LineNum 3 assigned to it.
Its OK for a LineNum to be associated with more than one CodeNum but not a CodeNum to be associated with more than one LineNum value.
There is an error in the example above where the 3rd row with CodeNum 4009 has LineNum 6 instead of 5, here’s where I want an error message to pop up saying something like Error row id 1023526.
The real table/data contains many rows and there is no pattern to the CodeNum values and LineNum values, (all the values are integers).
I hope that makes sense.
I’m struggling to think of a quick succinct way to code this error check method.
You could convert to a lookup and then search for groupings with a count > 1: