Here's a couple of different angles you could take.
First up, you could program a function that takes in a DataTable and returns back whether it possesses a certain authorization level:
bool AuthorizedForLevel(DataTable recordsForPONumber, int authLevel)
{
foreach(DataRow dr in recordsForPONumber.Rows)
{
if (dr.Field<int>("AuthLevel") == authLevel)
{
int? authorized = dr.Field<int?>("Authorized");
if (!authorized.HasValue) return false;
if (authorized.Value == 0) return false;
return true;
}
}
return false; // didn't have an entry, so they must not be authorized.
}
... and then, your logic is simply:
if (AuthorizedForLevel(resultDT, 1))
if (!AuthorizedForLevel(resultDT, 2))
if (!AuthorizedForLevel(resultDT, 3))
// what you want to do
The big advantage to this approach? It doesn't assume the order of the rows in your result datatable - hard coding row[0], row[1], row[2] has the disadvantage of assuming that all the rows are present and in a specific order. Additionally, it's nice and refactored, so the logic is very clear and concise in what's going on.
A second approach would be to format the data nicely on the SQL side. I mean, there's no reason you have to do the decoding from the C# across multiple rows.
-- some variable @poNum that's passed to your stored procedure
select
(select Authorized from myTable where PONumber = @poNum and AuthLevel = 1) as AuthorizedFor1,
(select Authorized from myTable where PONumber = @poNum and AuthLevel = 2) as AuthorizedFor2,
(select Authorized from myTable where PONumber = @poNum and AuthLevel = 3) as AuthorizedFor3
... aka, instead of getting three rows back and trying to parse it on the C# side, just change how you're getting the data from SQL so that you get back your data in a single row.
Anyway, hope that helps out! :-)
***** Edit, based on OP's comments: *****
As a few people have mentioned, Dictionary objects are NOT reliably sorted. It's not something you should depend on. (See Does the Enumerator of a Dictionary<TKey, TValue> return key value pairs in the order they were added?)
Short Story: If you continue forward using a Dictionary object, you're going to get burned in the future when the order doesn't come back like you expect it to.
But that's okay - you can shift over to something else. Two good options would be:
List<Tuple<string, BO.User>> versionA;
List<KeyValuePair<string, BO.User>> versionB;
Okay, now that I've gotten that big caution out of the way? You can use some nice handy Linq functions to get what you're looking for:
List<Tuple<string, BO.user>> listICareAbout;
if (someCondition)
listICareAbout = myMainList.Take(1).ToList();
else
listICareAbout = new List<Tuple<string, BO.user>>(myMainList);
If that doesn't make sense, do some googling for 'C# List Take', 'C# IEnumerable ToList', etc.