VS C# Not a valid boolean

I have this loop the examines a check box in a datagridview.  On my development computer it works fine. I just loaded this program onto a target computer to test and if they put a check in the box and this loop is executed we get the message "String was not recognized as a valid Boolean". How do I track down this error? What could it possibly be?

            foreach(DataGridViewRow row in dgvOpenSalesOrders.Rows)
            {
                try
                {
                    if  ( Convert.ToBoolean(((DataGridViewCell)row.Cells[7]).Value.ToString()) == false)
                    {
                        WriteRecord(Convert.ToDateTime(((DataGridViewCell)row.Cells[0]).Value.ToString()), Convert.ToDateTime(((DataGridViewCell)row.Cells[1]).Value.ToString()), ((DataGridViewCell)row.Cells[2]).Value.ToString(),
                         ((DataGridViewCell)row.Cells[3]).Value.ToString(), ((DataGridViewCell)row.Cells[4]).Value.ToString(), ((DataGridViewCell)row.Cells[5]).Value.ToString(),Convert.ToDecimal(((DataGridViewCell)row.Cells[6]).Value.ToString()),Convert.ToBoolean(((DataGridViewCell)row.Cells[7]).Value.ToString()), TRNSDATE, TRNSFLAG);
                    }
                }
                catch (Exception ex)
                {
                    string eMsg = "003: ERROR: " + ex.Message;
                    if (StackTraceWanted) eMsg += "\n" + ex.StackTrace;
                    MessageBox.Show(eMsg);
                }
            }
LVL 1
rwheeler23Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
>>"String was not recognized as a valid Boolean". How do I track down this error? What could it possibly be?

I guess the ToString is returning something other than true or false.  eg. a German language machine **could** be returning wahr or falsch

To track it down you could put a breakpoint and single step the lines of code, inspecting just what is in the string
rwheeler23Author Commented:
Does SQL have trouble with the '&'. I was just testing line by line and I noticed the first where this crash occurs one of the text fields has an '&' in it.
rwheeler23Author Commented:
Never mind about the '&'. What I just discovered is that it fails at the exact same row every time. Is there a limit to how many rows can be in a datagridview? This dataset is date sensitive. If I run it for any entire year it returns 354 records and it will fail. However, If I run it one month at a time it does not fail.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

AndyAinscowFreelance programmer / ConsultantCommented:
>>If I run it for any entire year it returns 354 records and it will fail.

That ought not to be a problem.  If it always the same row then is there something special in that row?
rwheeler23Author Commented:
Yes, but when I get to that row and there are only 30 records as opposed to 354, the loop goes right through with no problem. I think it is something inside SQL because the actual error message is no END Transaction found for Begin transaction. Let me ask the SQL group about this.
rwheeler23Author Commented:
I have found what is the problem but I do not know how to fix it. What this program does is shows all the orders prior to a certain date period. The user can they choose whether to archive the orders or not. How this is done is I added a Boolean check box to the 7th column of the dgv. Now I do not how I have done this but when the screen first appears on the screen it shows all the potential records and there is as date value at the bottom. If the user enters a different date I have given them a Display button. When they click on the button the screen is refreshed with only those orders that qualify with the new date. What I just discovered is that until the user clicks the Display button, the column for the checkbox is in the wrong column. It is column 7 but when I inserted break point column 7 has the values for column 6 which are numeric and explain why I get the message about not being a Boolean. Once I click the Display button, which has a dgv.columns.clear command, column 7 is now column 7 which is the Boolean column I added. I have no idea how to correct this. I can include the code if you want to see it. I must have something out of sequence.
AndyAinscowFreelance programmer / ConsultantCommented:
Maybe you should check the name (or ID or something) rather than just use the column number in that case.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwheeler23Author Commented:
Let me check how to use the name instead. I did not know you could do that.
rwheeler23Author Commented:
OK, I am stuck in a loop here and it must be something I am doing wrong. When I change to use the name of the column and not the number of the column, I get the ever popular message "Object not set to an instance of an object". So somehow when I initially open the form, the column checkbox column does not exist but after the user clicks the display button it does even though the user can see and check the box at all times. My dataset has 6 columns and I add a 7th column to the datadridview to allow the user to put a check in the box as an indicator as to whether to include the record or not. This 7th column is not part of the dataset. It is only added to the datagridview. Here is the code:

            DataGridViewCheckBoxColumn colCheckBox = new DataGridViewCheckBoxColumn();
            colCheckBox.HeaderText = "Keep";
            colCheckBox.Name = "colCheck";
            colCheckBox.Width = 36;
            dgvOpenSalesOrders.Columns.Insert(7, colCheckBox);
            dgvOpenSalesOrders.Columns["colCheck"].ValueType = typeof(Boolean);
rwheeler23Author Commented:
Thanks for the tips. I am still trying to track down why the user has to click the display button. It must have something to do with how VS opens the form. It appears when it initially opens my check box is not there. So the question would be how do I add the check box and then have the form open. I think I will open a new case for this question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.