See more:
Hello
i am trying to do that : equal text box value into emp class property type int and decimal
```txtDept.text = emp.DepID  // string = int
txtSalary.text = emp.salary // string = decimal
so ho i can convert that?
```
Posted 21-May-12 0:43am

Thank you for accepting the solution :)
VJ Reddy - 22-May-12 3:01am

you are very welcome i hope to be just 1 % of your experience i am new to work just 1 week starting work in my company so i face many problems and my time so tight
Haitham tarek - 22-May-12 5:12am

## Solution 3

Refer this:

http://lokeshbasana.wordpress.com/2009/07/16/asp-net-convert-string-to-date-date-to-string-string-to-intstring-to-doublestring-to-decimalobject-to-intobject-tostringstring-to-byte-array/[^]

```string a = “1234″;

int b = Convert.ToInt16(a);```

```string a = “1234.34″;
decimal b = decimal.Parse(a);```
Good idea. But ToInt16 converts to Short. 5!
VJ Reddy - 21-May-12 6:59am

ok. Thank you Reddy
sravani.v - 21-May-12 7:04am

5+
Mohamed Mitwalli - 21-May-12 7:14am

Thank you Mitwalli
sravani.v - 21-May-12 7:22am

Mohamed Mitwalli - 21-May-12 7:27am

thanks :) +5
Haitham tarek - 22-May-12 2:45am

Welcome Haitham
sravani.v - 22-May-12 3:57am

sravani.v - 22-May-12 6:43am

## Solution 4

```String to int
use=
Convert.ToInt32(string)

String to Decimal
Convert.ToDecimal(String);```
v2
VJ Reddy - 21-May-12 7:00am

5+
Mohamed Mitwalli - 21-May-12 7:21am

thanks :) +5
Haitham tarek - 22-May-12 2:46am

## Solution 5

Use the `ToString `method with required format as shown below:
```txtDept.Text = emp.DepID.ToString();
txtSalary.Text = emp.salary.ToString("N2");```
The question was not clear. If it is required to convert the `string` representation of the number to its native value then there are several approaches. One option is to use `Convert.ToInt32, Convert.ToDecimal` etc. methods as these will not `throw exception` even when the input value is `null `as shown below:
```emp.DepID=Convert.ToInt32(txtDept.Text);
emp.salary=Convert.ToDecimal(txtSalary.Text);```
v2
My 5!
sravani.v - 21-May-12 7:03am

Thank you, sravani :)
VJ Reddy - 21-May-12 7:05am

5+ for good explanation
Mohamed Mitwalli - 21-May-12 7:15am

Thank you, Mohamed :)
VJ Reddy - 21-May-12 7:19am

Mohamed Mitwalli - 21-May-12 7:27am

- well i already checked for null in other function so am sure in this step it will not get null... - the other thing here is( if ) i used the.tostring(); it wont work because it will show me the column name not the value and also it wont work well because i must use the text boxes to the their values as parameters to the database columns so am i understand it right or not?
Haitham tarek - 22-May-12 2:52am

+5 :D
Haitham tarek - 22-May-12 5:14am

## Solution 6

Hi,
You can use emp.DepID.ToString();
`txtSalary.text = emp.salary.ToString();`
v2
Good point. 5!
VJ Reddy - 21-May-12 7:00am

5+ but you should read solution 5 for VJ and his explanation
Mohamed Mitwalli - 21-May-12 7:16am

## Solution 8

Try This
```
txtDept.text =Convert.ToInt32( emp.DepID ) ;// string = int
txtSalary.text =Convert.ToDecimal( emp.salary); // string = decimal```
5+
Mohamed Mitwalli - 21-May-12 7:16am

Why do you keep copying other answers?
AspDotNetDev - 23-May-12 19:15pm

## Solution 2

Hi ,
Check this
```      emp.DepID =Convert.ToInt32( txtDept.text ) ;// string = int
emp.salary  =Convert.ToDecimal( txtSalary.text); // string = decimal```

Best Regards
M.Mitwalli
v2
Good answer. 5! only thing is the txtDept.text and emp.DepId are to be swapped. Similarly in other statement.
VJ Reddy - 21-May-12 6:57am

Maybe he want bind retrieved data to controls it can be like this var emp = (from x in db.emp select x).FirstOrDefault(); txtSalary.text =Convert.ToDecimal( emp.salary)
Mohamed Mitwalli - 21-May-12 7:13am

But I think the final statement may throw the error Cannot implicitly convert type 'decimal' to 'string'
VJ Reddy - 21-May-12 7:19am

Yes it will throw error if it contains letters like this Convert.ToDecimal("aa"); but if it already digit it will be okay Convert.ToDecimal("10.5");
Mohamed Mitwalli - 21-May-12 7:26am

I am thinking that txtSalary.Text is property of string type and a decimal value is being assigned to it. Thank you :)
VJ Reddy - 21-May-12 7:35am

yes you are right from the beginning didn't noticed
Mohamed Mitwalli - 21-May-12 7:39am

It will throw Error :( txtSalary.text it's already string and iam trying to assign to it decimal or int sure it will throw exception
Mohamed Mitwalli - 21-May-12 7:41am

OK. Finally our thoughts converged to the same point. Thank you :)
VJ Reddy - 21-May-12 7:52am

:) Thanks
Mohamed Mitwalli - 21-May-12 8:00am

hahahaa nice wise convo guys ;)
Haitham tarek - 22-May-12 2:54am

+5 mohammed ;)
Haitham tarek - 22-May-12 2:55am

Thanks Haitham :)
Mohamed Mitwalli - 22-May-12 2:59am

## Solution 9

ya this works for u...

```txtDept.text =Convert.ToInt32( emp.DepID ) ;//int
txtSalary.text =Convert.ToDecimal( emp.salary); //decimal```

## Solution 7

Write .ToString in both the statement.

```txtDept.text = emp.DepID.ToString();
txtSalary.text = emp.salary.ToString();
```

To Convert String Int or Decimal Use
```Convert.ToInt32(string_name);//To Convert into Int
Convert.ToDecimal(string_name);//To convert into decimal```
v2
VJ Reddy - 21-May-12 7:00am

Thanks Reddy :)
bhagirathimfs - 21-May-12 7:08am

5+
Mohamed Mitwalli - 21-May-12 7:16am