TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
simon taylor
NA
38
69.2k
Trouble with my variable conversion
Dec 11 2010 12:51 PM
Hi,
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:
targetOneDay =
Convert
.ToInt32(nine_to_fourteenhrstxbx.Text);
//tonine_to_fourteenhrstxbx.Text;
targetTwoDay =
Convert
.ToInt32(fifteen_to_fortfourglhtxtbx.Text);
targetFiveDay =
Convert
.ToInt32(fourtyfive_to_74txtbx.Text);
targetTenDay =
Convert
.ToInt32(min75glhtxtbx.Text);
targetTotal =
Convert
.ToInt32(totaltargettxtbx.Text);
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 assist me with my issue please.
Reply
Answers (
17
)
Please help - datagridview
Make Random Numbers More Random - Thankyou