Solved

Easy Boolean algebra problem

Posted on 2007-04-11
4
263 Views
Last Modified: 2009-12-16
I'm having a very dumb issue with my Boolean algebra and I can't find the error. I'm hoping someone can help me. Here's my code -- it's largely trace output for debugging:

(Just for context, it's in the middle of a for loop. The row object is of type DataRow.)

Trace.Write("Current row: " + row["user_id"] + ", " + row["file_id"]);

Trace.Write("row[\"can_upload\", DataRowVersion.Original] = " +
(row.HasVersion(DataRowVersion.Original) ? row["can_upload", DataRowVersion.Original] : "DataRowVersion.Original does not exist."));

Trace.Write("row[\"can_download\", DataRowVersion.Original] = " +
(row.HasVersion(DataRowVersion.Original ) ? row["can_download", DataRowVersion.Original] : "DataRowVersion.Original does not exist."));

Trace.Write("row[\"can_upload\", DataRowVersion.Current ] = " +
(row.HasVersion(DataRowVersion.Current) ? row["can_upload", DataRowVersion.Current] : " DataRowVersion.Current does not exist."));

Trace.Write("row[\"can_download\", DataRowVersion.Current] = " +
(row.HasVersion(DataRowVersion.Current) ? row["can_download", DataRowVersion.Current] : "DataRowVersion.Current does not exist."));

if(row.HasVersion(DataRowVersion.Original)) {
     Trace.Write("Upload, original equals current? " + (row["can_upload", DataRowVersion.Original] == row["can_upload", DataRowVersion.Current]).ToString());
     Trace.Write("Download, original equals current? " + (row["can_download", DataRowVersion.Original] == row["can_download", DataRowVersion.Current]).ToString());
}

if( row.HasVersion(DataRowVersion.Original) &&
     ((row["can_upload", DataRowVersion.Original] == row["can_upload", DataRowVersion.Current]) &&
      (row["can_download", DataRowVersion.Original] == row["can_download", DataRowVersion.Current])) )
{
     Trace.Write("No change for user: " + (int)row["user_id"]);
     continue;
}
Trace.Write("Permissions changed for user: " + (int)row["user_id"]);

Here's the output:
Current row: 1437, 2078      
row["can_upload", DataRowVersion.Original] = True  
row["can_download", DataRowVersion.Original ] = True  
row["can_upload", DataRowVersion.Current] = True  
row["can_download", DataRowVersion.Current] = True  
Upload, original equals current? False  
Download, original equals current? False  
Permissions changed for user: 1437

So, row["can_upload", DataRowVersion.Original] is true, row["can_upload", DataRowVersion.Current] is true, but they don't have the same boolean value? Can someone help me out here please?
0
Comment
Question by:tjgquicken
  • 2
4 Comments
 
LVL 12

Expert Comment

by:jkmyoung
ID: 18890294
Instead of using ==, I suggest using or, ||
0
 
LVL 12

Accepted Solution

by:
jkmyoung earned 50 total points
ID: 18890357
err sorry, brain fart. Ignore last comment.

You might have to cast your values as booleans, eg:

((bool)(row["can_upload", DataRowVersion.Original]) == (bool)(row["can_upload", DataRowVersion.Current]) )

Are you using C or something else?
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 18890448
>>Instead of using ==, I suggest using or, ||

??

==  --> Is Equal To
||  -->  OR

I don't follow the logic for that.




As for the problem itself, I would reccomend getting the actual values for DataRowVersion.Original and DataRowVersion.Current.  Then I would check to see if your row contains those versions.  

Keep in mind that some of the object used in .Net are very intelligent and actually keep track of previous states.  I thought this type of intelligence was limited to a dataset, but then a dataset is only a collection of datatables, which in turn is only a collection of datarows.  It is possible that the datarow tracks its previous state and may very well contain two different versions.
0
 

Author Comment

by:tjgquicken
ID: 18890518
I tried casting the two values to bools, and that worked. Now that I think about it, using Object.Equals() would probably also work.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to read text with RegEx... 2 26
How to Generate a Method from a keyboard shortcut in Visual Studio? 2 20
Input parameteres to DragOver 2 20
AvlTree-Node Data type 4 14
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question