Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Easy Boolean algebra problem

Posted on 2007-04-11
Medium Priority
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"]);
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?
Question by:tjgquicken
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 12

Expert Comment

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

Accepted Solution

jkmyoung earned 200 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?
LVL 22

Expert Comment

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.

Author Comment

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.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

636 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