I have database column as "Salary". I'm keeping salary records of employees in this column as smallMoney. With C# I can insert this column value like "2000". After that I saw that columns value is "2000,00" in database. I need to get this value back like "2000" as string to update in my program. Because my program works like this. So, to use this value again, how can I convert this smallMoney to something to use effectively for my program? (Int "2000" or String "2000" is ok for my program)
I researched but couldn't find solution. Could anyone say how I do this?
The SQL smallmoney
is equal to a C# decimal
.
So after retrieving it from the database, you could convert it to an int
. (You will lose the any decimal numbers though) OR you may use string formatting to only show the whole numbers.
For example:
// Create example value from database
decimal dSalary = 2000.00m;
int iSalary = Convert.ToInt32(dSalary);
Or you could keep it a decimal and just use string formatting, like this:
string Result = dSalary.ToString("0");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With