conversion (from sting to int?)

  • Thread starter Thread starter MP
  • Start date Start date
M

MP

I have following

In structure Employee is declared public int EmpId

Employee mp = new Employee();

mp.EmpId = txbName.Text;

Error:
Cannot implicitly convert type string to int

I have try with cast:
mp.EmpId = (int) txbName.Text;
It doesn't work

mp.EmpId.ToString = txbName.Text;
It doesn't work too?
 
MP said:
I have following

In structure Employee is declared public int EmpId

Employee mp = new Employee();

mp.EmpId = txbName.Text;

Error:
Cannot implicitly convert type string to int

I have try with cast:
mp.EmpId = (int) txbName.Text;
It doesn't work

mp.EmpId.ToString = txbName.Text;
It doesn't work too?

Convert.ToInt32()

This will throw a NumberFormatException if the
text in the textbox is not numeric.

You may want to put a validator on it to ensure
the input is valid.

-c
 
Thanks :)

Chad Myers said:
Convert.ToInt32()

This will throw a NumberFormatException if the
text in the textbox is not numeric.

You may want to put a validator on it to ensure
the input is valid.

-c
 
Back
Top