i am working on a project and i need to show a error message if the user enters string in a text box whose datatype is int??
it throws exception that input string is not in correct format...:(

Recommended Answers

All 5 Replies

Here you are

if(int.TryParse(TextBox1.Text))
//good
else
MessageBox.Show("Text couldn't be converted to integer");

Here you are

if(int.TryParse(TextBox1.Text))
//good
else
MessageBox.Show("Text couldn't be converted to integer");

It shows

Error 18 No overload for method 'TryParse' takes '1' arguments C:\Users\Manak\Desktop\smsfinal\StudentManagementSystem\StudentAttendance.cs 164 17 StudentManagementSystem

I became old man who doesn't remember code syntax :(

int result;
if(int.TryParse(TextBox1.Text, out result))
MessageBox.Show(stirng.Format("Result is {0}", result));
else
MessageBox.Show("Text couldn't be converted to integer");

I became old man who doesn't remember code syntax :(

int result;
if(int.TryParse(TextBox1.Text, out result))
MessageBox.Show(stirng.Format("Result is {0}", result));
else
MessageBox.Show("Text couldn't be converted to integer");

thanx mahn its solved

Just a little remark here.
When you have but a few error messages this is still a feasable system. But don't annoy a user with perhaps dozens of error messages. In the end it would become unmaintainable. Suppose you write the same sofware for the arab, russian and chinese market, who is going to translate and maintain all those messages?
Perhaps take a look at the ErrorProvider class or have a look at this humble example of yet another way of doing it: http://www.daniweb.com/code/snippet1094.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.