Typically, rounding of salary amounts uses the same algorithm as is implemented in
Math.Round
. The example below uses
Math.Round
to round data retrieved from Excel before using it in the
INSERT
statement. The example uses the
ToString()
method with a format to convert to a text string for use in the
INSERT
statement. Note that the value is
not enclosed in apostrophes because the BasicSalary column in the database should be defined as a
Numeric
,
Decimal
or
Money
data type.
The example below rounds to two decimal places which is common for salaries.
string ins = "insert into PaySalary1(BasicSalary,HRA) values (" + Math.Round(dtExcel.Rows[i][0],2).ToString("###########0.00") + ",'" + dtExcel.Rows[i][1] + "')";