i am trying to accumulate a total to be stored in my 'targetTotal' variable of type int which is then to be sent to my msaccess db into a field called 'targetTotal' of type LongInteger, the trouble i am having now is that after adding my totals given the following code snippet:
int targetOneDay =0; int targetTwoDay = 0; int targetFiveDay = 0; int targetTenDay = 0; int targetTotal =0; int total = 0; targetTotal = targetOneDay + targetTwoDay + targetFiveDay + targetTenDay;
i get an error which says the following: 'Input string was not in correct format' pointing to the target total variable. So i looked online for this particular error and based on my understanding i have to check if it is a null value and convert it accordingly. So what i first did was created another variable called 'total' of type int, removed the 'text' property of my target total and added the following if statement:
targetTotal = Convert.ToInt32(totaltargettxtbx); if (targetTotal != null) total = Convert.ToInt32(targetTotal); else total = 0;
now when i run my applicantion i get another error saying: Unable to cast object of type 'System.Windows.Forms.TextBox' to type 'System.IConvertible'. which is pointing to my targetTotal variable.
Can somebody kindly tell me why i'm getting these errors and how exactly i can resolve please.