nad nad - 1 month ago 14
ASP.NET (C#) Question

Input string was not in a correct format. Expected type in Decimal type

I am not inserting any value in

VOUCHER_NO
column and updating it.

But it is giving me error as


Input string was not in a correct format.Couldn't store <> in VOUCHER_NO Column. Expected type is Decimal.


Below is my code

drpayinfo[0]["VOUCHER_NO"] = e.Record["VOUCHER_NO"];


Update

I am using Oracle DB and its datatype is
NUMBER (10)

Answer

Seems your e.Record["VOUCHER_NO"] have some unwanted content which is not convertible to decimal. Try this way checking before assignment or conversion

if(e.Record["VOUCHER_NO"] != "")
{
  drpayinfo[0]["VOUCHER_NO"] = Convert.ToDecimal(e.Record["VOUCHER_NO"]);
}

But more safer way to detect and ignore bad content is

decimal result;

if (Decimal.TryParse(e.Record["VOUCHER_NO"], out result))
{
    drpayinfo[0]["VOUCHER_NO"] = result;
}
else
{
    // do stuff if failed to parese
}